Share
Explore BrainMass

A Java Class for Time

Modify class Time2 of Fig. 8.5 to include a tick method that increments the time stored in a Time2 object by one second. Provide method incrementMinute to increment the minute and method incrementHour to increment the hour. The Time2 object should always remain in a consistent state. Write a program that tests the tick method, the increment-Minute method and the incrementHour method to ensure that they work correctly. Be sure to test the following cases:

Attachments

Solution Preview

There are two files: Time2.java is the .java class to handle second ticks and the Time2Test.java that tests the The set methods incorporate error handling, therefore simply adding 1 to the previous values of second/minute/hour works. You can add the following four methods. Notice how incrementSecond() ...

Solution Summary

Solution includes two files: Time2.java is the .java class to handle second ticks and the Time2Test.java that tests the The set methods incorporate error handling, therefore simply adding 1 to the previous values of second/minute/hour works. You can add the following four methods. Notice how incrementSecond() triggers incrementMinute() when seconds exceed 59 and incrementMinute() triggers incrementHour when minute exceeds 59.

$2.19