This commit is contained in:
Chloe Fontenot 🏳️‍⚧️ 2023-02-09 12:55:55 -06:00
parent 697b231cc7
commit 6ce8c0d880
26 changed files with 427 additions and 2 deletions

Binary file not shown.

View File

@ -7,8 +7,8 @@
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<exec.mainClass>com.calebfontenot.lab3_calebfontenot.Lab3_CalebFontenot</exec.mainClass>
</properties>
</project>

View File

@ -0,0 +1,138 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
*/
package com.calebfontenot.lab3_calebfontenot;
/**
*
* @author caleb
*/
public class Fan {
// Constants
public static final int SLOW = 1;
public static final int MEDIUM = 2;
public static final int FAST = 3;
private int speed;
private boolean isOn;
private int radius;
private String color;
public Fan() {
this.speed = 1;
this.isOn = false;
this.radius = 5;
this.color = "blue";
}
/**
* Get the value of color
*
* @return the value of color
*/
public String getColor()
{
return color;
}
/**
* Set the value of color
*
* @param color new value of color
*/
public void setColor(String color)
{
this.color = color;
}
/**
* Get the value of radius
*
* @return the value of radius
*/
public int getRadius()
{
return radius;
}
/**
* Set the value of radius
*
* @param radius new value of radius
*/
public void setRadius(int radius)
{
this.radius = radius;
}
/**
* Get the value of isOn
*
* @return the value of isOn
*/
public boolean isOn()
{
return isOn;
}
/**
* Set the value of isOn
*
* @param isOn new value of isOn
*/
public void setOn(boolean isOn)
{
this.isOn = isOn;
}
/**
* Get the value of speed
*
* @return the value of speed
*/
public int getSpeed()
{
return speed;
}
/**
* Set the value of speed
*
* @param speed new value of speed
*/
public void setSpeed(int speed)
{
this.speed = speed;
}
@Override
public String toString()
{
String returnString;
if (this.isOn) {
returnString = "fan is on. ";
}
else {
returnString = "fan is off. ";
}
returnString += "{" + "speed=" + speed + ", radius=" + radius + ", color=" + color + '}';
return returnString;
}
public static void main(String[] args)
{
Fan fan1 = new Fan();
fan1.setSpeed(Fan.FAST);
fan1.setRadius(10);
fan1.setColor("yellow");
fan1.setOn(true);
System.out.println(fan1);
Fan fan2 = new Fan();
fan2.setSpeed(Fan.MEDIUM);
fan2.setRadius(5);
fan2.setColor("blue");
fan2.setOn(false);
System.out.println(fan2.toString());
}
}

View File

@ -0,0 +1,79 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.calebfontenot.lab3_calebfontenot;
import java.util.Scanner;
/**
*
* @author caleb
*/
public class FanList {
private Fan[] list;
// A constructor that creates a list of type fan
public FanList(int listSize)
{
list = new Fan[listSize];
createListObjects();
}
// Creates a list of Fan objects from User's input
private void createListObjects()
{
Scanner scan = new Scanner(System.in);
for (int i = 0; i < list.length; ++i) {
Fan fan = new Fan();
System.out.println("Enter FAN data for fan " + (i + 1)
+ ": color, radius, speed(1, 2 or 3) and if on (t, f)");
String color = scan.next();
int radius = scan.nextInt();
int speed = scan.nextInt();
String on = scan.next();
fan.setSpeed(speed);
fan.setRadius(radius);
fan.setColor(color);
if ("t".compareToIgnoreCase(on) == 0) {
fan.setOn(true);
} else {
fan.setOn(false);
}
list[i] = fan;
System.out.println("----------------------------------------");
}
}
@Override
public String toString()
{
String s = "FanList{" + "list=\n";
for (int i = 0; i < list.length; ++i) {
s += list[i].toString() + "\n-----------------------\n";
}
s += '}';
return s;
}
public void sortListByRadius()
{
for (int i = 0; i < list.length - 1; ++i) {
for (int j = i + 1; j < list.length; ++j) {
if (list[i].getRadius() > list[j].getRadius()) {
Fan temp = list[i];
list[i] = list[j];
list[j] = temp;
}
}
}
}
public static void main(String[] args)
{
FanList fanList = new FanList(3);
System.out.println(fanList);
fanList.sortListByRadius();
System.out.println(fanList.toString());
}
}

View File

@ -0,0 +1,119 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.calebfontenot.lab3_calebfontenot;
/**
*
* @author caleb
*/
public class Stock {
private String symbol;
private String name;
private double previousClosingPrice;
private double currentPrice;
/**
* Get the value of currentPrice
*
* @return the value of currentPrice
*/
public double getCurrentPrice()
{
return currentPrice;
}
/**
* Set the value of currentPrice
*
* @param currentPrice new value of currentPrice
*/
public void setCurrentPrice(double currentPrice)
{
this.currentPrice = currentPrice;
}
/**
* Get the value of previousClosingPrice
*
* @return the value of previousClosingPrice
*/
public double getPreviousClosingPrice()
{
return previousClosingPrice;
}
/**
* Set the value of previousClosingPrice
*
* @param previousClosingPrice new value of previousClosingPrice
*/
public void setPreviousClosingPrice(double previousClosingPrice)
{
this.previousClosingPrice = previousClosingPrice;
}
/**
* Get the value of name
*
* @return the value of name
*/
public String getName()
{
return name;
}
/**
* Set the value of name
*
* @param name new value of name
*/
public void setName(String name)
{
this.name = name;
}
/**
* Get the value of symbol
*
* @return the value of symbol
*/
public String getSymbol()
{
return symbol;
}
/**
* Set the value of symbol
*
* @param symbol new value of symbol
*/
public void setSymbol(String symbol)
{
this.symbol = symbol;
}
public double getChangePercent() {
return this.currentPrice - this.previousClosingPrice;
//(((this.previousClosingPrice - this.currentPrice) / Math.abs(this.previousClosingPrice)) * 100)
}
@Override
public String toString()
{
return "Stock{" + "symbol=" + symbol + ", name=" + name + ", previousClosingPrice=" + previousClosingPrice + ", currentPrice=" + currentPrice + "}"+ "\n" + "Change in Percent: " + this.getChangePercent();
}
public static void main(String[] args)
{
Stock stock1 = new Stock();
stock1.setSymbol("ORCL");
stock1.setName("Oracle Corporation");
stock1.setPreviousClosingPrice(34.5);
stock1.setCurrentPrice(34.35);
System.out.println(stock1);
}
}

View File

@ -0,0 +1,75 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.calebfontenot.lab3_calebfontenot;
import java.util.Scanner;
/**
*
* @author caleb
*/
public class StockList {
private Stock[] list;
// A constructor that creates a list of type stock
public StockList(int listSize)
{
list = new Stock[listSize];
createListObjects();
}
// Creates a list of Fan objects from User's input
private void createListObjects()
{
Scanner scan = new Scanner(System.in);
for (int i = 0; i < list.length; ++i) {
Stock stock = new Stock();
System.out.println("Enter Stock data for stock " + (i + 1)
+ ": symbol, name, previous closing price, and current price");
String symbol = scan.next();
String name = scan.next();
double previousClosingPrice = scan.nextDouble();
double currentPrice = scan.nextDouble();
stock.setSymbol(symbol);
stock.setName(name);
stock.setPreviousClosingPrice(previousClosingPrice);
stock.setCurrentPrice(currentPrice);
list[i] = stock;
System.out.println("----------------------------------------");
}
}
@Override
public String toString()
{
String s = "StockList{" + "list=\n";
for (int i = 0; i < list.length; ++i) {
s += list[i].toString() + "\n-----------------------\n";
}
s += '}';
return s;
}
public void sortByChangeInPercentage()
{
for (int i = 0; i < list.length - 1; ++i) {
for (int j = i + 1; j < list.length; ++j) {
if (list[i].getChangePercent() > list[j].getChangePercent()) {
Stock temp = list[i];
list[i] = list[j];
list[j] = temp;
}
}
}
}
public static void main(String[] args)
{
StockList stockList = new StockList(3);
System.out.println(stockList);
stockList.sortByChangeInPercentage();
System.out.println(stockList);
}
}

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.calebfontenot</groupId>
<artifactId>lab3_CalebFontenot</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<exec.mainClass>com.calebfontenot.lab3_calebfontenot.Lab3_CalebFontenot</exec.mainClass>
</properties>
</project>