forked from dravidjoseph/eecs448proj1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTime.java
More file actions
329 lines (287 loc) · 5.77 KB
/
Time.java
File metadata and controls
329 lines (287 loc) · 5.77 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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/**
* @file: Time.java
* @author: Ashley Hutton, Hannah Johnson, and Rabel Marte
* @date: 2/10/16
* @brief: Implementation file for Time class
*/
import java.util.Calendar;
public class Time {
private int hour;
private int minute;
private int second;
private boolean isMilitary = true;
private int militaryHour;
// true is pm false is am
private boolean amPm;
private boolean isMidnight = false;
/**
* @pre None
* @post Creates a Time object with defalut values of 0 for the variables hour, minute, and second.
* @return None
*/
public Time()
{
Calendar currentTime = Calendar.getInstance();
hour = 0;
minute = 0;
second = 0;
}
/**
* @pre Valid boolean and three ints. Validity of those determined by client
* @post Creates a Time object whose variable values are set to the three passed in ints. Boolean determines military time
* @return None
*/
public Time(boolean isMilitary, int hour, int minute, int second)
{
this.isMilitary = isMilitary;
this.hour = hour;
this.minute = minute;
this.second = second;
}
/**
* @pre None
* @post None
* @return return amPm
*/
public boolean getAmPm() {
return amPm;
}
/**
* @pre None
* @post None
* @return return isMidnight
*/
public boolean getIsMidnight() {
return isMidnight;
}
/**
* @pre passed in boolean midnight
* @post sets this.isMidnight to passed in midnight
* @return none
*/
public void setIsMidnight(boolean midnight) {
isMidnight = midnight;
}
/**
* @pre Valid boolean hourMode
* @post sets this.amPm to passed in hourMode
* @return None
*/
public void setAmPm(boolean hourMode) {
this.amPm = hourMode;
}
/**
* @pre None
* @post None
* @return return isMilitary
*/
public boolean getIsMilitary() {
return isMilitary;
}
/**
* @pre Valid int mode passed in
* @post sets this.isMilitary to mode passed in
* @return None
*/
public void setIsMilitary(boolean militaryMode) {
this.isMilitary = militaryMode;
}
/**
* @pre None
* @post None
* @return Return hour
*/
public int getHour() {
return hour;
}
/**
* @pre Valid hour integer passed in
* @post Sets this.hour to the passed in value
* @return None
*/
public void setHour(int hour) {
this.hour = hour;
}
/**
* @pre None
* @post None
* @return minute
*/
public int getMinute() {
return minute;
}
/**
* @pre Valid int milHour passed in
* @post Sets this.militaryHour to passed in milHour
* @return none
*/
public void setMilitaryHour(int milHour) {
this.militaryHour = milHour;
}
/**
* @pre None
* @post None
* @return military hour
*/
public int getMilitaryHour() {
return militaryHour;
}
/**
* @pre Valid integer minute passed in
* @post Sets this.minute to passed in minute
* @return None
*/
public void setMinute(int minute) {
this.minute = minute;
}
/**
* @pre None
* @post None
* @return Return second
*/
public int getSecond() {
return second;
}
/**
* @pre Valid integer second passed in
* @post Sets this.second to passed in second
* @return None
*/
public void setSecond(int second) {
this.second = second;
}
/**
* @pre None
* @post Updates the value for the variable "second". Takes into consideration that the numbers restart from 59 to 0.
* @return None
*/
public void updateSeconds()
{
if (second == 59)
{
second = 0;
updateMinutes();
}
else
{
second++;
}
}
public void updateSecondsTimer() {
if (second == 0) {
second = 59;
updateMinutesTimer();
}
else {
second--;
}
}
/**
* @pre None
* @post Updates the value for the variable "minute". Takes into consideration that the numbers restart from 59 to 0.
* @return None
*/
public void updateMinutes()
{
if (minute == 59)
{
minute = 0;
updateHours();
}
else
{
minute++;
}
}
public void updateMinutesTimer() {
if(minute == 0)
{
minute = 59;
updateHoursTimer();
}
else {
minute--;
}
}
/**
* @pre Have to pass in an boolean to determine the updates for the hour
* @post Updates the value for the variable "hour". Takes into consideration that the numbers restart from 12 to 1 for the 12 hour clock, and from 23 to 0 for the 24 hour clock.
* @return None
*/
public void updateHours()
{
militaryHour += hour;
// 12 Hour
if (!isMilitary)
{
//System.out.println("In 12 hour");
// account for AM/PM by incrementing military hour
// and then checking changing AM/PM variable
if(militaryHour == 23) { militaryHour = 0; }
else { militaryHour++; }
if(militaryHour >= 12) { amPm = true; }
else { amPm = false; }
// if time switched from 24, it needs to be converted
if(hour > 12) {
//System.out.println("Inside the check");
hour -= 12;
}
// increment hour accordingly
if (hour == 12) { hour = 1; }
else { hour++; }
// switch am/pm at midnight or noon
if(hour == 12 && minute == 0 && second == 0) {
if(amPm == false) {
amPm = true;
}
else if(amPm == true) {
amPm = false;
isMidnight = true;
//System.out.println("Changed midnight to true");
// here's where increment day is
// System.out.println(m_dayOfWeekOb.getDayOfWeek());
//m_dayOfWeekOb.incrementDayOfWeek();
}
}
}
// 24 hour
if (isMilitary)
{
// increment military hour in case user switches to 12 hour
if(militaryHour == 23) { militaryHour = 0; }
else { militaryHour++; }
if(militaryHour >= 12) { amPm = true; }
else { amPm = false; }
// increment hour accordingly
if (hour == 23) { hour = 0; }
else { hour++; }
if (hour == 0 && minute == 0 && second == 0){
isMidnight = true;
}
}
}
public void updateHoursTimer() {
if (!isMilitary)
{
if (hour == 1)
{
hour = 12;
}
else
{
hour--;
}
}
if (isMilitary)
{
if (hour == 0)
{
hour = 23;
}
else
{
hour--;
}
}
}
}