Hey all,
I've tried not to ask questions for like a week or two but, I've got the Introduction to Java Programming (sixth edition) and I'm doing the Exercise 7.2 'The Fan Class' where I am to; Design a class named Fan to represent a fan. They have the UML Diagram of:
Fan +SLOW = 1
+MEDIUM = 2
+FAST = 3
-speed: int The speed of this fan (default 1).
-on: Boolean Indicates whether the fan is on (default false).
-radius: double The radius of this fan (default 5).
-color: String The color of this fan (default white).
+Fan() Constructs a fan with default values.
+getSpeed(): int Returns the speed of this fan.
+setSpeed(speed: int): void Sets a new speed for this fan.
+isOn(): Boolean Returns true if this fan is on.
+setOn(on: boolean): void Sets this fan on to true or false.
+getRadius(): double Returns the radius of this fan.
+setRadius(radius: double): void Sets a new radius for this fan.
+getColor(): String Returns the color of this fan.
+setColor(color: String): void Sets a new color for this fan.
+toString(): String Returns a string representation for this fan.
So far, I've got this... I know that I'm supposed to be utilizing these other variables and constructors etc. but I don't know how or why. HELP!?! (lol)
public class Fan
{
//main method
public static void main(String[] args)
//variables
slow = 1;
medium = 2;
fast = 3;
boolean on = false;
int speed = 1;
double radius = 5;
String color = blue;
//make my fan
Fan()
{
}
//fan's radius
Fan(double radius = 5)
{
}
//get the colors
public boolean getColorValue()
{
if(getColor() == Color.blue)
{
//something goes here
return true;
}
else
{
//something goes here
return false;
}
//The to String
String toString();
{
String result;
if(on == true)
{
String speedString;
if(speed == slow)
speedString = "slow"
else if (speed == medium)
speedString = "medium"
else if (speed == fast)
speedString = "fast"
result = "Speed = " + speedString; + "Color = " + color + "Radius = " + radius;
}
else
result = "Color = " + Color + "Radius = " + radius + "fan is off"'
{
}
return result;
System.out.println(fan1.toString());
System.out.println(fan2.toStrint());