-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPanicButton.java
76 lines (66 loc) · 1.87 KB
/
PanicButton.java
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
// This class represents the Panic button class in the wireless security system.
public class PanicButton extends SecurityDevice {
// The device ID of the hardware.
public static final String deviceID = "Panicbutton";
// Boolean for alert
public boolean alert;
// Boolean for device armed
private boolean armed;
// Distance from BaseStation
private int distance;
// Initial values for WaterSensor.
public PanicButton() {
super(deviceID);
distance = 0;
alert = false;
armed = true;
}
// Chooses whether or not Panic Button is on silent or not
public String onSilentAlarmMode(boolean mode) {
if (mode) {
armed = false;
return ("Panic Button is now on Silent Mode.");
} else {
armed = true;
return ("Panic Button is off Silent Mode.");
}
}
// Sets the range you are from the device
public void setDistance(int range) {
distance = range;
}
// Method that allows you to press panic button.
public void pressButton() {
if (isInRange()) {
super.sendAlert("ALARM ACTIVATED", deviceID);
startAlarm();
notifyAuthority();
} else {
}
}
// Method that chooses correct alarm output.
private void startAlarm() {
if (armed && isConnected) {
alert = true;
super.sendAlert("ALARM! PANIC BUTTON PRESSED!", deviceID);
} else {
super.sendAlert("Panic Button was pressed on silent mode.", deviceID);
}
}
// Method that notifies if the authorities have been called.
private void notifyAuthority() {
if (armed && isConnected) {
super.sendAlert("The nearby authorities are on their way!", deviceID);
} else {
super.sendAlert("The authorities have not been contacted.", deviceID);
}
}
// used to check for if device is in range of Base Station.
private boolean isInRange() {
if (distance < 100) {
return true;
} else {
return false;
}
}
}