Question

In: Computer Science

(Code in Java please) You need to implement the GarageDoor, GarageDoorUpCommand and GarageDoorDownCommand classes (similar to...

(Code in Java please)

You need to implement the GarageDoor, GarageDoorUpCommand and GarageDoorDownCommand classes (similar to Light, LightOnCommand and LightOffCommand), AND (edited)

Implement the CeilingFan class (with state, see p. 220), AND CeilingFanHighCommand (p. 221), CeilingFanMediumCommand, CeilingFanLowCommand, CeilingFanOffCommand (WITH Undo), AND

TEST your CeilingFan classes (see pp. 222 and 223), AND

Finally, implement and Test the MacroCommand class on pp. 224-227


EXAMPLE output for homework assignment……………


======= The COMMAND PATTERN =============
guest house garage door is UP guest house garage door is down
family room tv is ON family room tv is off
bathroom ceiling fan is on MEDIUM bathroom ceiling fan is on OFF bathroom ceiling fan is on HIGH bathroom ceiling fan is on OFF
patio hottub is heating to a steaming 104 deg F and is bubbling ! patio hottub is cooling to 98 deg F
------ Remote Control -------
[slot 0] com.company.LightOnCommand
[slot 1] com.company.LightOnCommand
[slot 2] com.company.CeilingFanOnCommand
[slot 3] com.company.StereoOnWithCDCommand
[slot 4] com.company.GarageDoorUpCommand
[slot 5] com.company.CeilingFanHighCommand
[slot 6] com.company.CeilingFanMediumCommand
[slot 7] com.company.CeilingFanLowCommand
[slot 8] com.company.CeilingFanOnOffCommand
Living room light is ON --- Living room light is off
Kitchen light is ON --- Kitchen light is off
Living room ceiling fan is on HIGH --- Living room ceiling fan is off
Living room stereo is ON , CD , Volume: 11 --- Living room stereo is off , RADIO , Volume: 5
guest house garage door is UP --- guest house garage door is down
bathroom ceiling fan is on OFF bathroom ceiling fan is on LOW bathroom ceiling fan is on MEDIUM bathroom ceiling fan is on HIGH
bathroom ceiling fan is on MEDIUM bathroom ceiling fan is on LOW bathroom ceiling fan is on OFF
================= Macros running...
Living room light is ON Living room stereo is ON , CD , Volume: 11 bathroom ceiling fan is on HIGH
Living room light is off Living room stereo is off , Volume: 5 bathroom ceiling fan is on OFF
Process finished with exit code 0

Solutions

Expert Solution

import java.util.*;

class Light{

    boolean status;

    String roomName;

    public Light(String roomName){

        this.roomName = roomName;

    }

    public Light(boolean status){

        this.status = status;

        

    }

    public void LightOnCommand(){

        this.status = true;


        System.out.println("I am glowing in " + this.roomName );

        

    }

    public void LightOffCommand(){

        this.status = false;

        System.out.println("I am off in " + this.roomName);

    }

}

class CeilingFan{

    boolean status = false;

    String speed;

    String roomName;

    public CeilingFan(String roomName){

        this.roomName = roomName;

    }

    public void FanOffOn(){

        this.status = !this.status;

        if(this.status){

            System.out.println("Fan is On in " + this.roomName);

        }else{

            System.out.println("Fan Off in " + this.roomName);

        }

    }

    public void CeilingFanHighSpeed(){

        this.speed = "High";

        System.out.println("Running High in " + this.roomName);

    }

    public void CeilingFanMediumSpeed(){

        this.speed = "Medium";

        System.out.println("Running Meddium in " + this.roomName);

    }

    public void CeilingFanLowSpeed(){

        this.speed = "Low";

        System.out.println("Running Low in " + this.roomName);

    }

}

class Stereo{

    boolean status = false;

    String roomName;

    int volume = 0;

    public Stereo(String roomName){

        this.roomName = roomName;

    }

    public void StereoOnWithCDCommand(){

        this.status = !this.status;

        if(this.status){

            System.out.println("The Stereo is ON in " + this.roomName);

        }else{

            System.out.println("THe stereo is Off " + this.roomName);

        }

    }

    public void IncreseVolume(){

        if(this.status){

            this.volume = this.volume + 1;

            System.out.println("Volume: " + this.volume);

        }

        

    }

    public void DecreaseVolume(){

        if(this.status){

            if(this.volume >= 1)

                this.volume = this.volume -1 ;

            System.out.println("Volume: " + this.volume);

        }

      

    }

}


class GarageDoor{

    boolean status = false;

    String roomName;

    public GarageDoor(String roomName){

        this.roomName = roomName;

    }

    public void GarageDoorUpCommand(){

        this.status = true;

        System.out.println("The Garage door is open in " + roomName);

    }

    public void GarageDoorDownCommand(){

        this.status = false;

        System.out.println("The garage door is down for  " + this.roomName);

    }

    

    

}


public class Solution{

    public static void main(String[] args) {

        System.out.println("Remote Control");

        System.out.println("Select Room");

        System.out.println("1. Living Room");

        System.out.println("2. Guest Room");

        System.out.println("3. Kitchen");

        System.out.println("4. Bathroom");

        System.out.println("5. Family Room");

        Scanner sc = new Scanner(System.in);

        int roomNo = sc.nextInt();

        String roomName = "";


        switch (roomNo) {

            case 1:

                roomName = "Living Room";

                break;

            case 2:

                roomName = "Guest Room";

                break;

            

            case 3:

                roomName = "Kitchen";

                break;

            case 4:

                roomName = "BaathRoom";

                break;

            case 5:

                roomName = "Family Room";

        

            default:

                roomName = "UnKnown Room";

                break;

        }


        Light light = new Light(roomName);

        light.LightOnCommand();

        light.LightOffCommand();

        CeilingFan cf = new CeilingFan(roomName);

        cf.FanOffOn();

        cf.FanOffOn();

        cf.CeilingFanHighSpeed();

        cf.CeilingFanMediumSpeed();

        cf.CeilingFanLowSpeed();

        Stereo stereo = new Stereo(roomName);

        stereo.StereoOnWithCDCommand();

        stereo.IncreseVolume();

        stereo.IncreseVolume();

        stereo.DecreaseVolume();

        stereo.StereoOnWithCDCommand();

        GarageDoor garageDoor = new GarageDoor(roomName);

        garageDoor.GarageDoorUpCommand();

        garageDoor.GarageDoorDownCommand();


    }

}



Related Solutions

Java code. You will need to make classes that could be used to stage a battle...
Java code. You will need to make classes that could be used to stage a battle as described below. You have been tasked to create a number of items that can be used in an online game. All items can be used on a game character who will have a name, a number of health-points and a bag to hold the items.   Here are examples of items that can be made: Item type of item effectOnHealth other info Widow's Cloak...
For this question, you need to implement Java code for the following Modified Ciphertext encryption and...
For this question, you need to implement Java code for the following Modified Ciphertext encryption and attack for known patterns to find the code. Please read the modified Ciphertext carefully and examples before implementing them.   Modified Ciphertext is working as follows: If a plain text (only letters ignore uppercase or lowercase) and sequences of numbers are given, it encrypts the given plain text by shifting each letter in a message the characters based on the given numbers one forward direction...
The answer should be in JAVA. You will design and implement two classes to support a...
The answer should be in JAVA. You will design and implement two classes to support a client program, RockPaperScissorsGame.java, to simulate Rock-Paper-Scissors game. Read and understand the client program to find out the requirements for the HandShape and Player classes. The rules of the Rock-Paper-Scissors game are:     Scissors✌️ beats Paper✋ that beats Rock✊ that beats Scissors✌️ Additionally, to simplify the game logic (and complexify a little bit the HandSahpe class) , two players cannot show the same hand shape....
The answer should be in JAVA. You will design and implement two classes to support a...
The answer should be in JAVA. You will design and implement two classes to support a client program, RockPaperScissorsGame.java, to simulate Rock-Paper-Scissors game. Read and understand the client program to find out the requirements for the HandShape and Player classes. The rules of the Rock-Paper-Scissors game are:     Scissors✌️ beats Paper✋ that beats Rock✊ that beats Scissors✌️ Additionally, to simplify the game logic (and complexify a little bit the HandSahpe class) , two players cannot show the same hand shape....
**Only need the bold answered In Java, implement the Athlete, Swimmer, Runner, and AthleteRoster classes below....
**Only need the bold answered In Java, implement the Athlete, Swimmer, Runner, and AthleteRoster classes below. Each class must be in separate file. Draw an UML diagram with the inheritance relationship of the classes. 1. The Athlete class a. All class variables of the Athlete class must be private. b.is a class with a single constructor: Athlete(String lName, String fName, int birthYear, int birthMonth, int birthDay, char gender). All arguments of the constructor should be stored as class variables. There...
This program focuses on programming with Java Collections classes. You will implement a module that finds...
This program focuses on programming with Java Collections classes. You will implement a module that finds a simplified Levenshtein distance between two words represented by strings. Your program will need support files LevenDistanceFinder.Java, dictionary.txt, while you will be implementing your code in the LevenDistanceFinder.java file. INSTRUCTIONS The Levenshtein distance, named for it's creator Vladimir Levenshtein, is a measure of the distance between two words. The edit distance between two strings is the minimum number of operations that are needed to...
a java code In this lab you will implement an inorder traversal, and a search for...
a java code In this lab you will implement an inorder traversal, and a search for a 2-3-4 tree. The inorder traversal will print the contents (integers) of the tree, and the search method will return a boolean, indicating whether a given key was found in the tree. Examine the provided template. The main method is provided for you, as well as a template of the Node and 2-3-4 classes. The main method will read either "inorder" or an integer...
// the language is java, please implement the JOptionPane Use method overloading to code an operation...
// the language is java, please implement the JOptionPane Use method overloading to code an operation class called CircularComputing in which there are 3 overloaded methods and an output method as follows: • computeObject(double radius) – compute the area of a circle • computeObject(double radius, double height) – compute area of a cylinder • computeObject(double radiusOutside, double radiusInside, double height) – compute the volume of a cylindrical object • output() use of JOptionPane to display instance field(s) and the result...
All code in JAVA please 1. Implement Insertion Sort 2. Implement Selection Sort *For problem 1...
All code in JAVA please 1. Implement Insertion Sort 2. Implement Selection Sort *For problem 1 and 2, please: a. Let the program generate a random array. b. Output both the original random array and the sorted version of it
IN JAVA. I have the following code (please also implement the Tester to test the methods...
IN JAVA. I have the following code (please also implement the Tester to test the methods ) And I need to add a method called public int remove() that should remove the first integer of the array and return it at the dame time saving the first integer and bring down all other elements. After it should decrease the size of the array, and after return and save the integer. package ourVector; import java.util.Scanner; public class ourVector { private int[]...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT