Java Reference
In-Depth Information
if
(sec < 10)
System.out.print("0");
System.out.print(sec);
}
//Method to increment the time by one second
//Postcondition: The time is incremented by one second
//If the before-increment time is 23:59:59, the time
//is reset to 00:00:00
public void
incrementSeconds()
{
sec++;
if
(sec > 59)
{
sec = 0;
incrementMinutes();
//increment minutes
}
}
//Method to increment the time by one minute
//Postcondition: The time is incremented by one minute
//If the before-increment time is 23:59:53, the time
//is reset to 00:00:53
public void
incrementMinutes()
{
8
min++;
if
(min > 59)
{
min = 0;
incrementHours();
//increment hours
}
}
//Method to increment the time by one hour
//Postcondition: The time is incremented by one hour
//If the before-increment time is 23:45:53, the time
//is reset to 00:45:53
public void
incrementHours()
{
hr++;
if
(hr > 23)
hr = 0;
}
//Method to compare two times
//Postcondition: Returns true if this time is equal to
// otherClock; otherwise returns false
public boolean
equals(Clock otherClock)
Search WWH ::
Custom Search