The Java class TimeOfDay is incomplete, and your task is to bring it as close to completion as you can. To aid you in that, the Java application TimeOfDayTester is provided. Its purpose, as its name suggests, is to test the various features of TimeOfDay. (You are free to modify the test program in any way you see fit.) Another tool that can be used for testing is jGrasp's Workbench utility, as you may be familiar with from past work.
A sample dialog between a user and TimeOfDayTester appears near the end of this document.
It is highly recommended that you take several minutes to study the source code of TimeOfDay in order to come to an understanding of how its features are implemented.
Once you have done that, you will be in a position to make the modifications (including filling in the missing bodies of several "stubbed" methods) that are requested below. The comments preceding each method describe its intended behavior. Use TimeOfDayTester each time (you think) you have completed a method in order to test it.
As an example, suppose that count is of type int and has a value in the range [0..100). Then the expression String.format("%02d", count) evaluates to a 2-digit numeral corresponding to the value of count. Thus, if count had value 57, the resulting String would be "57", and if count had value 8, the resulting String would be "08".
|
String minuteStr, amPmStr; // < code that assigns an appropriate value to minuteStr > // < code that assigns an appropriate value to amPmStr > return hour + ":" + minuteStr + amPmStr; |
As with toString24Format(), using String.format() here would work nicely.
Welcome to the TimeOfDayTester program. Enter time of day (e.g., 5:46AM, 12:07PM): 11:58AM After initialization, time is 11:58AM Available commands: ------------------- Q (Quit) H (Help) FM (test goForwardByMinute()) FH (test goForwardByHour()) BM (test goBackwardsByMinute()) BH (test goBackwardsByHour()) E (test isEarlierThan()) 24 (test toString24Format()) > FM After calling goForwardByMinute(), the time is 11:59AM > FM After calling goForwardByMinute(), the time is 12:00PM > FM After calling goForwardByMinute(), the time is 12:01PM > BM After calling goBackwardsByMinute(), the time is 12:00PM > BM After calling goBackwardsByMinute(), the time is 11:59AM > FH After calling goForwardByHour(), the time is 12:59PM > BH After calling goBackwardsByHour(), the time is 11:59AM > E isEarlierThan() says that 11:59AM is NOT earlier than 8:23AM isEarlierThan() says that 11:59AM is earlier than 5:17PM > 24 The 24-hour format for 11:59AM is 11:59 > FM After calling goForwardByMinute(), the time is 12:00PM > FM After calling goForwardByMinute(), the time is 12:01PM > 24 The 24-hour format for 12:01PM is 12:01 > FH After calling goForwardByHour(), the time is 1:01PM > 24 The 24-hour format for 1:01PM is 13:01 > Q Goodbye. |