-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathClock.java
More file actions
35 lines (30 loc) · 845 Bytes
/
Clock.java
File metadata and controls
35 lines (30 loc) · 845 Bytes
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
public class Clock {
private int hh;
private int mm;
private int ss;
public Clock(int hh, int mm, int ss) {
this.hh = hh;
this.mm = mm;
this.ss = ss;
}
public boolean outOfTime() {
return (hh == 0 && mm == 0 && ss == 0);
}
public void decr() {
if (this.mm == 0 && this.ss == 0) {
this.ss = 59;
this.mm = 59;
this.hh--;
} else if (this.ss == 0) {
this.ss = 59;
this.mm--;
} else this.ss--;
}
public String getTime() {
String fHrs = String.format("%02d", this.hh);
String fMins = String.format("%02d", this.mm);
String fSecs = String.format("%02d", this.ss);
String fTime = fHrs + ":" + fMins + ":" + fSecs;
return fTime;
}
}