Design and implement your own simple class to represent any household item of your choice (toaster, fan, hair dryer, piano ...) Your class should have a constructor, one additional method and at least one member variable (e.g. boolean isOn to turn the item on or off). Be sure you demonstrate your class works properly by constructing an instance of it and calling your method.

Respuesta :

Answer:

public class Fan {

/** Main method */

public static void main(String[] args) {

 final int SLOW = 1;  // Fan speed slow

 final int MEDIUM = 2; // Fan speed medium

 final int FAST = 3;  // Fan speed fast

 // Create two Fan objects

 Fan fan1 = new Fan();

 Fan fan2 = new Fan();

 

 fan1.setSpeed(FAST);

 fan1.setRadius(10);

 fan1.setColor("yellow");

 fan1.turnOn();

 

 fan2.setSpeed(MEDIUM);

 fan2.setRadius(5);

 fan2.setColor("blue");

 fan2.turnOff();

 System.out.println(fan1.toString());

 System.out.println(fan2.toString());

}

}

ACCESS MORE