
Change the given source code for Home Automation application into Command Pattern. I have listed the following source code
1. Bathroom.java
public class Bathroom extends Room {
private String hotWater;
}
2. Bedroom.java
public class Bedroom extends Room {
private String bed;
}
3. Client.java
public class Client {
public static void main(String[] args) {
House house = new House();
house.addRoom(new LivingRoom());
house.addRoom(new Bedroom());
house.addRoom(new Bedroom());
house.addRoom(new Bedroom());
house.addRoom(new Kitchen());
house.addRoom(new Bathroom());
house.rooms.forEach(Room::switchLights);
}
}
4.FloorLamp.java
public class FloorLamp {
private Light light;
public FloorLamp(){
this.light = new Light();
}
public void switchLights(){
light.switchLights();
System.out.println(this.getClass()+"'s light is "+this.light.isSwitchedon());
}
}
5.House.java
import java.util.ArrayList;
import java.util.List;
public class House {
List<Room> rooms;
public House(){
rooms = new ArrayList<>();
}
public void addRoom(Room room)
{
rooms.add(room);
}
}
6.Kitchen.java
public class Kitchen extends Room{
private String oven;
}
7.Light.java
public class Light {
private boolean switchedon = false;
public boolean isSwitchedon()
{
return switchedon;
}
/*public void setSwitchedon(boolean switchedon)
{
this.switchedon = switchedon;
}*/
public void switchLights()
{
switchedon = !switchedon;
//System.out.println(this.getClass()+"'s light is "+this.switchedon);
}
}
8. LivingRoom.java
public class LivingRoom extends Room{
private String windows;
private String slidingDoors;
private FloorLamp floorLamp;
public LivingRoom(){
floorLamp = new FloorLamp();
floorLamp.switchLights();
}
}
9. Room.java
public class Room {
private Light light;
public Room() {
this.light = new Light();
}
public void switchLights()
{
light.switchLights();
//light.setSwitchedon(!light.isSwitchedon());//if on turns off, if off turns on
System.out.println(this.getClass()+"'s light is "+this.light.isSwitchedon());
}
}

Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images

- Given the following code and instructions:Is the provided implemented correctly for said instructions?The main class Ride contains: public abstract boolean ableToRun(int numberofRuns);public abstract boolean checkRide(String[] components);public abstract double costPerPassenger(int numberOfStops);arrow_forwardjavaarrow_forwardPlease solve this using java and attach output screenshot and implementation screenshot. Using this clock class please: public class Clock { private int hr; private int min; private int sec; public Clock() { setTime(0, 0, 0); } public Clock(int hours, int minutes, int seconds) { setTime(hours, minutes, seconds); } public void setTime(int hours, int minutes, int seconds) { if (0 <= hours && hours < 24) hr = hours; else hr = 0; if (0 <= minutes && minutes < 60) min = minutes; else min = 0; if(0 <= seconds && seconds < 60) sec = seconds; else sec = 0; } public int getHours() { return hr; } public int getMinutes() { return min; } public int getSeconds() { return sec; } public void printTime() { if (hr < 10) System.out.print("0"); System.out.print(hr + ":"); if (min < 10) System.out.print("0"); System.out.print(min + ":"); if (sec < 10) System.out.print("0"); System.out.print(sec); } public void incrementSeconds() { sec++; if (sec >…arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





