Ask Question
28 December, 23:12

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. Hint: check out the week 6 module readings under "additional readings". The guitar example is a good model for thisDesign 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. Hint: check out the week 6 module readings under "additional readings". The guitar example is a good model for this ...

+2
Answers (1)
  1. 29 December, 00:42
    0
    class fan{

    private String model;

    private boolean isOn;

    //Constructor goes here

    public fan (String model, boolean isOn) {

    this. model = model;

    this. isOn = isOn;

    }

    / / An additional method goes here

    public boolean turnOn (boolean yes) {

    if (yes) {

    this. isOn=true;

    System. out. println ("Fan is blowing");

    return true;

    }

    else

    this. isOn=false;

    System. out. println ("Fan is off");

    return false;

    }

    }

    Explanation:

    Demonstrating the working of the class in a main method. Below is a complete code

    public class fanTest {

    public static void main (String[] args) {

    fan fan1 = new fan ("Binatone", false);

    fan1. turnOn (false);

    }

    }

    class fan{

    private String model;

    private boolean isOn;

    //Constructor goes here

    public fan (String model, boolean isOn) {

    this. model = model;

    this. isOn = isOn;

    }

    / / An additional method goes here

    public boolean turnOn (boolean yes) {

    if (yes) {

    this. isOn=true;

    System. out. println ("Fan is blowing");

    return true;

    }

    else

    this. isOn=false;

    System. out. println ("Fan is off");

    return false;

    }

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Design and implement your own simple class to represent any household item of your choice (toaster, fan, hair dryer, piano ...) Your class ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers