private int totalSeconds; public void tick() { this.totalSeconds++; this.totalSeconds = this.totalSeconds % (24 * 3600) ; } public void incrementMinute() { this.totalSeconds += 60; this.totalSeconds = this.totalSeconds % (24 * 3600) ; } public void incrementHour() { this.totalSeconds += 3600; this.totalSeconds = this.totalSeconds % (24 * 3600) ; } public Time1 () { this(0, 0, 0); // invoke constructor with three arguments } // Time1 constructor: hour supplied, minute and second defaulted to 0 public Time1(int hour) { this(hour, 0, 0); // invoke constructor with three arguments } // Time1 constructor: hour and minute supplied, second defaulted to 0 public Time1(int hour, int minute) { this(hour, minute, 0); // invoke constructor with three arguments } // Time1 constructor: hour, minute and second supplied public Time1(int hour, int minute, int second) { setTime(hour,minute,second); // invoke setTime to validate time } // Time1 constructor: another Time1 object supplied public Time1(Time1 time) { // invoke constructor with three arguments this(time.getHour(), time.getMinute(), time.getSecond()); } // Set Methods // set a new time value using universal time; // validate the data public void setTime(int hour, int minute, int second) { int sec = 0; if (hour >= 0 && hour = 0 && minute = 0 && second = 0 && hour = 0 && minute = 0 && second < 60) { int seconds = this.totalSeconds % 60; this.totalSeconds = this.totalSeconds – seconds + second; } else throw new IllegalArgumentException("second must be 0-59"); } public int getHour() { return totalSeconds / 3600; } // get minute value public int getMinute() { return ( totalSeconds % 3600 ) / 60; } // get second value public int getSecond() { return totalSeconds % 60; } // convert to String in universal-time format (HH:MM:SS) public String toUniversalString() { return String.format( "%02d:%02d:%02d", getHour(), getMinute(), getSecond()); } // convert to String in standard-time format (H:MM:SS AM or PM) @Override public String toString() { return String.format("%d:%02d:%02d %s", ((getHour() == 0 || getHour() == 12) ? 12 : getHour() % 12), getMinute(), getSecond(), (getHour() < 12 ? "AM" : "PM")); } String toStandardString() { return this.toString(); } }