/home/caleb/ASDV-Java/Semester 2/Assignments/lab3_CalebFontenot/src/main/java/com/calebfontenot/lab3_calebfontenot/FanList.java |
package com.calebfontenot.lab3_calebfontenot;
import java.util.Scanner;
@author
public class FanList {
private Fan[] list;
public FanList(int listSize)
{
list = new Fan[listSize];
createListObjects();
}
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());
}
}