-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTime.java
More file actions
23 lines (22 loc) · 710 Bytes
/
Time.java
File metadata and controls
23 lines (22 loc) · 710 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/**
* Class containing time represented as hours (must be 0-99), minutes (0-59) and seconds (0-59).
*/
public class Time {
public final int hours;
public final int minutes;
public final int seconds;
public Time(int hours, int minutes, int seconds) {
if(hours < 0 || hours > 99) {
throw new IllegalArgumentException("Hours must be between 0 and 99 inclusive.");
}
if(minutes < 0 || minutes > 59) {
throw new IllegalArgumentException("Minutes must be between 0 and 59 inclusive.");
}
if(seconds < 0 || seconds > 59) {
throw new IllegalArgumentException("Seconds must be between 0 and 59 inclusive.");
}
this.hours = hours;
this.minutes = minutes;
this.seconds = seconds;
}
}