-
Notifications
You must be signed in to change notification settings - Fork 2
/
Time.java
172 lines (147 loc) · 2.77 KB
/
Time.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
162
163
164
165
166
167
168
169
170
171
172
/**
* @file: Time.java
* @author: Richard Aviles and Jinuk Park
* @date: 2/10/16
* @brief: Implementation file for Time class
*/
public class Time {
private int hour;
private int minute;
private int second;
private boolean isMilitary;
/**
* @pre None
* @post Creates a Time object with defalut values of 0 for the variables hour, minute, and second.
* @return None
*/
public Time()
{
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 Return hour
* @return hour
*/
public int getHour() {
return hour;
}
/**
* @pre Have to pass in an int
* @post Sets the variable "hour" to the passed in value
* @return None
*/
public void setHour(int hour) {
this.hour = hour;
}
/**
* @pre None
* @post None
* @return the value for the variable "minute"
*/
public int getMinute() {
return minute;
}
/**
* @pre Have to pass in an int
* @post Sets the variable "minute" to the passed in value
* @return None
*/
public void setMinute(int minute) {
this.minute = minute;
}
/**
* @pre None
* @post None
* @return the value for the variable "second".
*/
public int getSecond() {
return second;
}
/**
* @pre Have to pass in an int
* @post Sets the variable "second" to the passed in value
* @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++;
}
}
/**
* @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++;
}
}
/**
* @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()
{
if (!isMilitary)
{
if (hour == 12)
{
hour = 1;
}
else
{
hour++;
}
}
if (isMilitary)
{
if (hour == 23)
{
hour = 0;
}
else
{
hour++;
}
}
}
}