Ask Question
5 May, 00:04

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

+1
Answers (1)
  1. 5 May, 02:54
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers