Language: Java
Your task is to complete the logic to manage a twenty-four-hour clock (no dates, just time) that tracks
the hours, minutes, and sections, and various operations to adjust the time. The framework for your
clock is in the Time class with the four methods you must complete.
1.) advanceOneSecondâ A user calls this method to advance the clock by one second.
a. When the seconds value reaches 60, it rolls over to zero.
b. When the seconds roll over to zero, the minutes advance.
So 00:00:59 rolls over to 00:01:00.
c. When the minutes reach 60, they roll over and the hours advance.
So 00:59:59 rolls over to 01:00:00.
d. When the hours reach 24, they roll over to zero.
So 23:59:59 rolls over to 00:00:00.
2.) compareTo â The user wants to know if a second time is greater than or less than the time
object called, assuming both are on the same date.
a. Returns -1 if this Time is before otherTime.
b. Returns 0 if this Time is the same as otherTime.
c. Returns 1 if this Time is after otherTime.
3.) add â Adds the hours, minutes, and seconds of another time (the offset) to the current time
object. The time should ârolloverâ if it exceeds the end of a 24 hour period.
4.) subtract â Subtracts the hours, minutes, and seconds of another time (the offset) from
the current time object. The time should âroll backâ if it precedes the beginning of a 24 hour
period.
________________________________________________________________________
package clock;
/**
* Objects of the Time class hold a time value for a
* European-style 24 hour clock.
* The value consists of hours, minutes and seconds.
* The range of the value is 00:00:00 (midnight) to 23:59:59 (one
* second before midnight).
*/
public class Time {
private int hours;
private int minutes;
private int seconds;
/**
* Add one second to the current time.
* When the seconds value reaches 60, it rolls over to zero.
* When the seconds roll over to zero, the minutes advance.
* So 00:00:59 rolls over to 00:01:00.
* When the minutes reach 60, they roll over and the hours advance.
* So 00:59:59 rolls over to 01:00:00.
* When the hours reach 24, they roll over to zero.
* So 23:59:59 rolls over to 00:00:00.
*/
public void advanceOneSecond()
{
}
/**
* Compare this time to otherTime.
* Assumes that both times are in the same day.
* Returns -1 if this Time is before otherTime.
* Returns 0 if this Time is the same as otherTime.
* Returns 1 if this Time is after otherTime.
*/
public int compareTo(Time otherTime)
{
return 0;
}
/**
* Add an offset to this Time.
* Rolls over the hours, minutes and seconds fields when needed.
*/
public void add(Time offset)
{
}
/**
* Subtract an offset from this Time.
* Rolls over (under?) the hours, minutes and seconds fields when needed.
*/
public void subtract(Time offset)
{
}