-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTime.java
More file actions
29 lines (28 loc) · 866 Bytes
/
Time.java
File metadata and controls
29 lines (28 loc) · 866 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
public class Time {
private int second;
private int minute;
private int hour;
public void time(int hour, int minute, int second){
setHour(hour);
setMinute(minute);
setSecond(second);
}
void setHour(int hour){
if(hour>=0 && hour<24)
this.hour=hour;
}
public void setSecond(int second) {
if (second >= 0 && second < 60)
this.second = second;
}
public void setMinute(int minute) {
if (minute >= 0 && minute < 60)
this.minute = minute;
}
public String toUniversalString(){
return String.format("%02d:%02d:%02d",hour, minute, second);
}
public String toString(){
return String.format("%d:%02d:%02d %s",((hour == 0)|| hour==12)?12:hour %12, minute,second, (hour<12?"AM":"PM"));
}
}