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

Question 2: Fan.java and va Design a class named Fan (Fan java) to represent a f

ID: 3804157 • Letter: Q

Question

Question 2: Fan.java and va Design a class named Fan (Fan java) to represent a fan. The class contains: An int field named speed that specifies the speed of the fan. A boolean field named fanStatus that specifies whether the fan is on (default false). A double field named radius that specifies the radius of the fan (default 5). A string field named color that specifies the color of the fan (default blue). A no-arg (default) constructor that creates a default fan. A constructor that creates a fan with four parameters: speed, fanStatus, radius, and color. A method named toString0 that returns a string description for the fan. The method returns the fan speed, color, radius, and fan status (either on or off) in one combined string. Write a TestFan program that asks the user to enter the fan speed, radius, fan status, and color. The program creates a fan object by using the constructor with four parameters. Then it should display the fan description by invoking their toString() method.

Explanation / Answer

import java.util.Scanner;
public class Fan{
  

public static void main(String[] args){
Scanner reader = new Scanner(System.in);
System.out.println("Enter speed");
int speed1 = reader.nextInt();
System.out.println("Enter fanstatus1");
boolean fanstatus1 = reader.nextInt();
System.out.println("Enter radius");
double radius1 = reader.nextInt();
System.out.println("Enter color");
string color1 = reader.nextInt();
TestFan fd = new fandemo(speed1,fanstatus1,radius1,color1);

}}
class TestFan{
int speed;
boolean fanStatus;
double radius;
string color;

public TestFan(int speed1, boolean fanstatus1, double radius1, string color1){
this.speed = speed1;
this.fanstatus = fanstatus1;
this.radius = radius1;
this.color = color1;

}
public string toString(){
  
return speed1+" "+fanstatus1" "+" "+radius1+" "+color1;
}

}

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