forked from grapemoli/MGOT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Water.java
161 lines (133 loc) · 3.89 KB
/
Water.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//Water.java
//grace nguyen
//march 10, 2022
import java.io.*;
class Water extends Attribute implements Serializable {
//attributes
int daysOverwatered;
int daysUnderwatered;
double waterConsumption;
public static void main(String[] args) {
//class testing
Water grace = new Water(1D);
for(int i = 0; i < 10; i++) {
grace.dailyWaterConsumption();
System.out.println(grace.getDaysUnderwatered());
System.out.println(grace.getStatus());
System.out.println(grace.isUnderwatered());
}
} //end main
//constructors
public Water() {
super("Water Meter", 5D);
this.daysOverwatered = 0;
this.daysUnderwatered = 0;
this.waterConsumption = 1D;
} //end constructor
public Water(double waterConsumption) {
super("Water Meter", 5D);
this.daysOverwatered = 0;
this.daysUnderwatered = 0;
this.waterConsumption = waterConsumption;
} //end constructor
public Water(double waterConsumption, Double status) {
super("Water Meter", status);
this.daysOverwatered = 0;
this.daysUnderwatered = 0;
this.waterConsumption = waterConsumption;
} //end constructor
//getters and setters
public void setWaterConsumption(double waterConsumption) {
this.waterConsumption = waterConsumption;
} //end setWaterConsumption
public double getWaterConsumption() {
return(this.waterConsumption);
} //end getWaterConsumption
public int getDaysOverwatered() {
return(this.daysOverwatered);
} //end getDaysOverwatered
public int getDaysUnderwatered() {
return(this.daysUnderwatered);
} //end getDaysUnderwatered
//boolean methods; checking statuses
public boolean isUnderwatered() {
//return true if the days underwatered is greater than 7 days
boolean underwatered = false;
if(this.daysUnderwatered >= 7) {
underwatered = true;
} //end if
return(underwatered);
} //end isUnderwatered
public boolean hasRootRot() {
//return true if the days overwatered is greater than 7 days
boolean rootRot = false;
if(this.daysOverwatered >= 7) {
rootRot = true;
} //end if
return(rootRot);
} //end hasRootRot
//passage-of-time methods
//i.e. methods meant to be used to show time has passed
public void checkWater() {
//increase overwatered if status is at 7-10
//increase underewated if status is 0-3
if(this.status > 7) {
this.daysOverwatered++;
}else{
this.daysOverwatered = 0;
} //end if-else
if(this.status < 3) {
this.daysUnderwatered++;
}else{
this.daysUnderwatered = 0;
} //end if-else
} //end dailyWaterCheck
public void dailyWaterConsumption() {
//plants consume water a little bit everyday
this.decrement(this.waterConsumption);
} //end dailyWaterConsumption
//action methods
public void water() {
this.status = 10d;
} //end water
//implement abstract classes
public void setStatus(Double status) {
if(status > 10D){
this.status = 10D;
}else if(status < 0D){
this.status = 0D;
}else{
this.status = status;
} //end if-else
} //end setStatus
public void decrement() {
if(this.status >= 1d) {
this.status--;
}else{
this.status = 0d;
} //end if-else
} //end decrement
public void decrement(double amount) {
//polymorphic behavior that takes into account
//the bounds of the water attribute
if(this.status <= amount) {
this.status = 0d;
}else {
this.status = this.status - amount;
} //end if-else
} //end decrement
public void increment() {
if(this.status >= 9d) {
this.status = 10D;
}else{
this.status++;
} //end if-else
} //end increment
public void increment(double amount) {
if(this.status < (10D - amount)) {
this.status = this.status + amount;
}else{
this.status = 10D;
} //end if-else
} //end increment
} //end class def