public class Fan {
final int SLOW = 1;
final int MEDIUM = 2;
final int FAST = 3;
private int speed;
private boolean on;
private double radius;
private String color;
public Fan(){
speed = SLOW;
on = false;
radius = 5;
color = "Blue";
}
public Fan(int speed, boolean on, double radius, String color) {
}
public void setSpeed(int speed){
this.speed = speed;
}
public int getSpeed(){
return speed;
}
public void setOn(boolean on){
this.on = on;
}
public boolean isOn(){
return on;
}
public void setRadius(double radius){
this.radius = radius;
}
public double getRadius(){
return radius;
}
public void setColor(String color){
this.color = color;
}
public String getColor(){
return color;
}
public String toString(){
if(on == false)
return "\nFan Speed: " + getSpeed() + "\nColor: " + getColor() + "\nRadius: " + getRadius();
else
return "\nColor: " + getColor() + "\nRadius: " + getRadius() + " (Fan is Off)";
}
}
class TestFan{
public static void main(String[] args){
Fan[] arrFan = new Fan[2];
arrFan[0] = new Fan(FAST, true, 10, "Yellow");
arrFan[1] = new Fan(MEDIUM, false, 5, "Blue");
for(int i = 0; i < arrFan.length; i++)
System.out.println(arrFan[i].toString());
}
}
my TestFan class wanna to assign value, but there's error occur with my array assignment, if i no misstaken, i think failed to get final value, so how? :(