-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBridge.java
More file actions
75 lines (64 loc) · 1.72 KB
/
Bridge.java
File metadata and controls
75 lines (64 loc) · 1.72 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
package structural;
interface RemoteCtrlInterface{
public boolean powerOn();
public void nextChannel();
public void previousChannel();
public void volumeUp();
public void volumeDown();
}
class RemoteCtrl implements RemoteCtrlInterface{
public boolean power;
@Override
public boolean powerOn() {
if(power){
System.out.println("Power Off");
power = false;
return !power;
}else{
System.out.println("Power On");
power = true;
return !power;
}
}
@Override
public void nextChannel() {
System.out.println("Next Channel");
}
@Override
public void previousChannel() {
System.out.println("Previous Channel");
}
@Override
public void volumeUp() {
System.out.println("Volume Up");
}
@Override
public void volumeDown() {
System.out.println("Volume Down");
}
}
class Television{
private RemoteCtrlInterface remote;
public void setRemote(RemoteCtrlInterface remote){
this.remote = remote;
}
public void actions(String signal){
switch (signal) {
case "on" -> this.remote.powerOn();
case "next" -> this.remote.nextChannel();
case "previous" -> this.remote.previousChannel();
case "volumeUp" -> this.remote.volumeUp();
case "volumeDown" -> this.remote.volumeDown();
}
}
}
public class Bridge {
public static void main(String[] args) {
Television tv = new Television();
tv.setRemote(new RemoteCtrl());
tv.actions("volumeDown");
tv.actions("volumeUp");
tv.actions("on");
tv.actions("next");
}
}