During last week's lab, you worked on completing one version of the TimeOfDay class. This week you are given a similar task, with the difference being that your starting point is a version of TimeOfDay that uses a single instance variable, minutesSinceMidnight (of type int), to serve as the underlying representation of a time of day (rather than the three instance variables hour, minute, and isAM, as in last week's version of the Java class).
To illustrate, minutesSinceMidnight having value 312 would be a representation of 5:12AM, as that time occurs 312 minutes after midnight. The intent (and requirement) is that your completed version of the class must have minutesSinceMidnight as its lone instance variable. Also, as indicated by the class invariant mentioned in the source code, the value of this variable must always remain in the range [0 .. MINUTES_PER_DAY).
As in last week's lab, you are encouraged to make use of the Java program TimeOfDayTester for the purpose of testing your work. (You are free to modify the test program in any way that 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 easy to identify those methods that need to be worked on, as each one has a comment that either identifies it as a "STUB" or includes one of the words "INCORRECT" or "MISSING".
Note that moving backwards by one minute is the same as moving forward by one fewer than MINUTES_PER_DAY! Similarly, moving backwards by an hour is the same as moving forward by MINUTES_PER_DAY - MINUTES_PER_HOUR minutes (i.e.., 23 hours).
As for producing a two-digit minute value, remember that —assuming that glorp is an integer whose value is in the range [0..100)— the expression
yields a two-digit numeral (reflecting the value of glorp) with a leading zero if needed.
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. |