This is my assignment
Write a class named Fan to model fans. The properties are speed, on, radius, and color. You need to provide the accessor methods for the properties, and the toString method for returning a string consisting of all the string values of all the properties in this class. Suppose the fan has three fixed speeds. Use constants 1, 2, and 3 to denote slow, medium, and fast speeds.
and my professor gave me an outline of the class and what I have to do is Write a client program(test application) to test the Fanclass. In the client program, create a Fan object.
Assign maximum speed, radius 10, color yellow, and turn it on.
Display the object by invoking its toString method.
I have gone till the end, created Fan class without any errors and also a client program to test the class but I cannot display whether the fan is ON/OFF. I simply blind coded the On class here. SO In my test class, I cannot print whether the fan is on or off, it simply shows me an error.
My Fan class is here
public class Fan { public final int SLOW = 1; public final int MEDIUM = 2; public final int FAST = 3; private int speed = SLOW; private boolean on = false; private double radius = 5; private String color = "white"; public Fan ( ) { } public Fan ( int newSpeed, boolean newOn, double newRadius, String newColor ) { setSpeed(newSpeed); setRadius(newRadius); setColor(newColor); } public int getSpeed ( ) { return speed; } public void setSpeed ( int speed ) { if (speed == SLOW) { System.out.println("Speed is 1"); } else if (speed == MEDIUM) { System.out.println("Speed is 2"); } else if (speed == FAST) { System.out.println("Speed is 3(Maximum Speed)"); } else { System.out.println("Invalid Speed"); } } public boolean isOn ( boolean newOn ) { return newOn; } public void setOn ( boolean newOn ) { if (on = false) { System.out.println("Fan is Turned on"); } else { System.out.println("Fan is turned off"); } } public double getRadius ( ) { return radius; } public void setRadius ( double newRadius ) { if (newRadius <= 0) { System.out.println("Radius cannot be zero or negative"); } else { radius = newRadius; } } public String getColor ( ) { return color; } public void setColor ( String newColor ) { color = newColor; } @Override public String toString ( ) { return "Dimensions are" + radius; } }
My Code for testing the class
public class TestApplication { public static void main (String[] args) { Fan testfan1 = new Fan(3, false, 10, "blue"); System.out.println(testfan1.getSpeed() + " " + testfan1.getColor() + " " + testfan1.getRadius() + " " + [COLOR="#FF0000"]testfan1.isOn()[/COLOR]); } }
SO as u see all the code work except testfan1.isOn, error says (req: boolean found: no args), even if I give testfan.isOn(false); no error shows up but it shows up 'false' in the output but I want it to display "Fan is turned on"