-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoteControlTest.java
More file actions
80 lines (63 loc) · 3.21 KB
/
RemoteControlTest.java
File metadata and controls
80 lines (63 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package CommandPattern.BasicRemote;
public class RemoteControlTest {
public static void main(String[] args){
RemoteControl remote = new RemoteControl();
Light livingRoomLight = new Light("Living Room");
Light kitchenLight = new Light("Kitchen");
CeilingFan ceilingFan = new CeilingFan("Living Room");
GarageDoor garageDoor = new GarageDoor("");
Stereo stereo = new Stereo("Living Room");
LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight);
LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight);
LightOnCommand kitchenLightOn = new LightOnCommand(kitchenLight);
LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight);
CeilingFanOn ceilingFanOn = new CeilingFanOn(ceilingFan);
CeilingFanOff ceilingFanOff = new CeilingFanOff(ceilingFan);
GarageDoorUpCommand garageDoorUp = new GarageDoorUpCommand(garageDoor);
GarageDoorDownCommand garageDoorDown = new GarageDoorDownCommand(garageDoor);
StereoOnWithCDCommand stereoOnWithCD = new StereoOnWithCDCommand(stereo);
StereoOff stereoOffWithCD = new StereoOff(stereo);
// Party mode
Command[] partyOn = { livingRoomLightOn, kitchenLightOn, ceilingFanOn, stereoOnWithCD };
Command[] partyOff = { livingRoomLightOff, kitchenLightOff, ceilingFanOff, stereoOffWithCD };
MacroCommand partyOnMacro = new MacroCommand(partyOn);
MacroCommand partyOffMacro = new MacroCommand(partyOff);
remote.setCommand(0, livingRoomLightOn, livingRoomLightOff);
remote.setCommand(1, kitchenLightOn, kitchenLightOff);
remote.setCommand(2, ceilingFanOn, ceilingFanOff);
remote.setCommand(3, stereoOnWithCD, stereoOffWithCD);
remote.setCommand(4, partyOnMacro, partyOffMacro);
System.out.println(remote);
System.out.println("------Living Room light-------");
remote.onButtonWasPushed(0);
remote.offButtonWasPushed(0);
System.out.println(remote);
System.out.println("--Undo button was pressed--");
remote.undoButtonWasPushed();
System.out.println("------Kitchen Light-------");
remote.onButtonWasPushed(1);
remote.offButtonWasPushed(1);
System.out.println(remote);
System.out.println("--Undo button was pressed--");
remote.undoButtonWasPushed();
System.out.println("------Ceiling fan-------");
remote.onButtonWasPushed(2);
remote.onButtonWasPushed(2);
remote.offButtonWasPushed(2);
System.out.println(remote);
System.out.println("--Undo button was pressed--");
remote.undoButtonWasPushed();
System.out.println("------Stereo-------");
remote.onButtonWasPushed(3);
remote.offButtonWasPushed(3);
System.out.println(remote);
System.out.println("--Undo button was pressed--");
remote.undoButtonWasPushed();
System.out.println("------Party Mode-------");
remote.onButtonWasPushed(4);
remote.offButtonWasPushed(4);
System.out.println(remote);
System.out.println("--Undo button was pressed--");
remote.undoButtonWasPushed();
}
}