Note: On this web page, as well as others you will encounter while enrolled in CMPS 144/144L, there will be hyperlinks directed to files containing the source code of Java classes. Due to restrictions imposed by those who administer the University's website, those files (other than some that existed before these restrictions took effect) must adhere to the rule that their names include no upper case letters. Now, by convention names of Java classes do include upper case letters, and the Java compiler requires that the name of a file containing a Java class must match the name of that class (with the extension .java). The result is that you must deal with inconvenience that, when you are about to save such a file after having loaded it into your web browser, you will likely have to modify the file name suggested by the browser so that it matches the name of the Java class. Another inconvenience is that some Java files you download may include something like "ZZ" in their names. That is a convention used by your instructor to indicate that the file contains Java code in need of completion. Thus, such occurrences of "ZZ" should be omitted from the name of the file when you save it. End of note.
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. |