-
Notifications
You must be signed in to change notification settings - Fork 1
/
Time.java
33 lines (27 loc) · 817 Bytes
/
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
package statements;
public class Time {
private int hours;
private int minutes;
private int seconds;
public Time(int hours, int minutes, int seconds) {
this.hours = hours;
this.minutes = minutes;
this.seconds = seconds;
}
public int getInMinutes() {
int hourInMinutes = 60;
return hours * hourInMinutes + minutes;
}
public int getInSeconds() {
int minuteInSeconds = 60;
return getInMinutes() * minuteInSeconds + seconds;
}
public boolean earlierThan(Time secondTime) {
int firstTimeSec = this.getInSeconds();
int secondTimeSec = secondTime.getInSeconds();
return firstTimeSec < secondTimeSec;
}
public String toString(){
return hours + ":" + minutes + ":" + seconds;
}
}