-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCeilingFanOn.java
More file actions
31 lines (26 loc) · 758 Bytes
/
CeilingFanOn.java
File metadata and controls
31 lines (26 loc) · 758 Bytes
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
package CommandPattern.BasicRemote;
public class CeilingFanOn implements Command{
CeilingFan ceilingFan;
int prevSpeed;
public CeilingFanOn(CeilingFan ceilingFan) {
this.ceilingFan = ceilingFan;
}
public void execute() {
prevSpeed = ceilingFan.getSpeed();
ceilingFan.high();
}
public void undo() {
if(prevSpeed == CeilingFan.HIGH){
ceilingFan.high();
} else if (prevSpeed == CeilingFan.MEDIUM){
ceilingFan.medium();
} else if (prevSpeed == CeilingFan.LOW){
ceilingFan.low();
} else if (prevSpeed == CeilingFan.OFF){
ceilingFan.off();
}
}
public String toString() {
return "CeilingFanOn";
}
}