Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem: Write a class named Fan to model fans. The properties are speed, on, ra

ID: 3680657 • Letter: P

Question

Problem: 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.

The outline of the class is given as follows:

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 speed, boolean on, double radius, String color ) { }

public int getSpeed ( ) { }

public void setSpeed ( int speed ) { }

public boolean isOn ( ) { }

public void setOn ( ) { }

public double getRadius ( ) { }

public void setRadius ( double radius ) { }

public String getColor ( ) { }

public void setColor ( String color ) { }

public String toString ( ) { }

}

Write a client program(test application) to test the Fan class. 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.

Develop a similar test class (driver) as done for the Rectangle class to validate the class definition as well as the equals method, if implemented

***Which class would i run to ensure the program is running properly***

Explanation / Answer

/******************* Fan.java ********************/

public class Fan {

private int SLOW = 1;
private int MEDIUM = 2;
private int FAST = 3;
private int speed;
private boolean on;
private double radius;
private String color;

public Fan()
{
speed = SLOW;
on = false;
radius = 5;
color = "white";
}

public Fan( int speed, boolean on, double radius, String color) {
this.speed = speed;
this.on = on;
this.radius = radius;
this.color = color;
}

public int getSlow(){
return SLOW;
}

public int getMedium() {
return MEDIUM;
}

public int getFast() {
return FAST;
}

public int getSpeed() {
return speed;
}

public boolean ison() {
return on;
}

public double getradius() {
return radius;
}

public String getcolor() {
return color;
}

public void setSlow( int SLOW) {
this.SLOW = SLOW;
}

public void setMedium( int MEDIUM) {
this.MEDIUM = MEDIUM;
}

public void setFast( int FAST) {
this.FAST = FAST;
}

public void setSpeed(int speed) {
this.speed = speed;
}

public void seton(boolean on) {
this.on = on;
}

public void setRadius(double radius) {
this.radius = radius;
}

public void setColor(String color) {
this.color = color;
}

public String toString() {
if(on == true ) {
System.out.println("The speed of the fan is " + speed + ", the color of the the fan is " + color + ", and the radius of the fan is " +radius + ".");
}
else {
System.out.println("The fan is off but the color is " + color +" and the radius is " + radius + ".");
}
  
return "0";
}
}

/*********** TestFan.java**************************/

public class TestFan {

   public static void main(String[] args) {

   Fan f1 = new Fan();
       f1.toString();
       Fan f2 = new Fan(3,true,10,"yellow");
       f2.toString();
       Fan f3 = new Fan(4,false,16,"grey");
       f3.toString();

       Fan f4 = new Fan();
       f4.toString();
       Fan f5 = new Fan(4,true,9,"pink");
       f5.toString();
       Fan f6 = new Fan(6,false,19,"red");
       f6.toString();
      
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote