-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAmericanDevice.java
More file actions
50 lines (43 loc) · 1.37 KB
/
AmericanDevice.java
File metadata and controls
50 lines (43 loc) · 1.37 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
package structural.adapter;
public class AmericanDevice implements PlugInDevice {
private final static Integer neededVoltage = 110;
private final PowerSocket socket;
private Boolean powered;
public AmericanDevice(PowerSocket socket) {
this.socket = socket;
this.powered = Boolean.FALSE;
}
@Override
public Integer neededVoltage() {
return neededVoltage;
}
@Override
public void plugIn() {
if (!powered) {
Integer provideVoltage = socket.provideVoltage();
if (provideVoltage.equals(neededVoltage())) {
powered = Boolean.TRUE;
Main.println("American device is working safely on " + provideVoltage + "V");
} else if (provideVoltage.equals(0)) {
Main.errPrintln("American device no voltage in socket");
} else {
Main.errPrintln("American device unsafe voltage!");
}
} else {
Main.errPrintln("American device is already turn on");
}
}
@Override
public void Unplug() {
if (powered) {
powered = Boolean.FALSE;
Main.println("American device is turn off");
} else {
Main.errPrintln("American device is already turn off");
}
}
@Override
public Boolean isPowered() {
return powered;
}
}