-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHottub.java
More file actions
77 lines (63 loc) · 1.58 KB
/
Hottub.java
File metadata and controls
77 lines (63 loc) · 1.58 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
//package headfirst.designpatterns.command.remote;
public class Hottub {
boolean on;
int temperature;
public final static int MAX_TEMPERATURE = 110;
public final static int MIN_TEMPERATURE = 80;
public Hottub() {
temperature = 105;
}
public void on() {
on = true;
}
public void off() {
on = false;
}
public void bubblesOn() {
if (on) {
System.out.println("Hottub is bubbling!");
}
}
public void bubblesOff() {
if (on) {
System.out.println("Hottub is not bubbling");
}
}
public void jetsOn() {
if (on) {
System.out.println("Hottub jets are on");
}
}
public void jetsOff() {
if (on) {
System.out.println("Hottub jets are off");
}
}
public boolean setTemperature(int temperature) {
if (on){
int prevTemp = this.temperature;
if(temperature < MIN_TEMPERATURE){
temperature = MIN_TEMPERATURE;
System.out.println("Hottub temperature cannot go any lower.");
}
if(temperature > MAX_TEMPERATURE){
temperature = MAX_TEMPERATURE;
System.out.println("Hottub temperature cannot go any higher.");
}
this.temperature = temperature;
if (prevTemp != this.temperature) return true;
}
return false;
}
public int getTemperature() {
return temperature;
}
public void heat() {
temperature = 105;
System.out.println("Hottub is heating to a steaming 105 degrees");
}
public void cool() {
temperature = 98;
System.out.println("Hottub is cooling to 98 degrees");
}
}