Ask Question
27 October, 01:42

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

+3
Answers (1)
  1. 27 October, 01:52
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers