-
Notifications
You must be signed in to change notification settings - Fork 0
/
Watch.java
64 lines (51 loc) · 1.43 KB
/
Watch.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
package lab2;
/**
* A simple Watch. A Watch keeps track of a long value in seconds.
* Users can change the time value of the Watch through other methods.
* A Watch provides a method to get and set the time value of the Watch.
*
*
*
*/
public class Watch {
/* To be able to complete this Class, you need to read the API of this class
*
* Hint: Use the WatchTest class to help you test you work
*
* */
private long startTime = 0;
public Watch() {
}
public Watch(long value) {
this.startTime = value;
}
public long getStartTime() {
return startTime;
}
public void setStartTime(long startTime) {
this.startTime = startTime;
}
public void incrbyHours(int value) {
this.startTime = value * 3600 + startTime;
}
public void decrbyHours(int value) {
this.startTime = startTime - value * 3600;
}
public void incrbyMinutes(int value) {
this.startTime = startTime + value * 60;
}
public void decrbyMinutes(int value) {
this.startTime = startTime - value * 60;
}
public int getTimeinHours() {
return (int)startTime/3600;
}
public int getTimeinMinutes() {
return (int)startTime/60;
}
public java.lang.String toString() {
int minutes = (int)startTime % 3600 / 60;
int seconds = (int)startTime % 60;
return "Watch Time is " + getTimeinHours() + " Hours, " + minutes + " Minutes, and " + seconds + " Seconds.";
}
}