/* An instance of this class represents a time of day, precise to the ** minute (e.g., 7:38am). ** ** Authors: R. McCloskey and < STUDENTS' NAMES > */ public class TimeOfDay { // class constants // --------------- static final int MINUTES_PER_HOUR = 60; static final int HOURS_PER_HALF_DAY = 12; static final int MINUTES_PER_DAY = 2 * HOURS_PER_HALF_DAY * MINUTES_PER_HOUR; // instance variable // ----------------- int minutesSinceMidnight; // class invariant: // 0 <= minutesSinceMidnight < MINUTES_PER_DAY // constructors // ------------ /* Initializes this TimeOfDay object to represent the time of day ** described by the three parameters. ** precondition: 1 <= h <= HOURS_PER_HALF_DAY && 0 <= m < MINUTES_PER_HOUR */ public TimeOfDay(int h, int m, boolean isAM) { setTo(h,m,isAM); } /* Initializes this object to represent noon. */ public TimeOfDay() { this(HOURS_PER_HALF_DAY, 0, false); } // observers // --------- /* Returns a String describing the time of day represented by this object. ** Examples: "7:38AM", "11:06PM" */ public String toString() { String hourStr, minuteStr, amPmStr; // MISSING code to assign appropriate values to the // three local variables declared above. return hourStr + ':' + minuteStr + amPmStr; } /* Returns a String describing the time of day represented by this object, ** in the 24-hour format (sometimes referred to as the "military" format). ** Such a string has the form hh:mm, where hh is a two-digit numeral ** (with a leading zero if necessary) indicating the number of full hours ** to have passed since midnight and mm is a two-digit numeral ** (with leading zero if necessary) indicating the number of full minutes ** to have passed since the beginning of the current hour. ** (E.g., 3:27PM is "15:27", 12:08AM is "00:08"). */ public String toString24Format() { return "???"; // STUB } /* Reports whether or not this time of day falls earlier in the day ** than does the time of day represented by (formal parameter) t. */ public boolean isEarlierThan(TimeOfDay t) { return true; // STUB } // mutators // -------- /* Sets this time of day to that described by the three parameters. ** precondition: 1 <= h <= HOURS_PER_HALF_DAY && 0 <= m < MINUTES_PER_HOUR */ public void setTo(int h, int m, boolean isAM) { // STUB } /* Advances this time of day by one minute (possibly rolling over into ** the following day). */ public void goForwardByMinute() { // INCORRECT when rolling over from one day to the next!! minutesSinceMidnight = minutesSinceMidnight + 1; } /* Advances this time of day by one hour (possibly rolling over into ** the following day). */ public void goForwardByHour() { // INCORRECT when rolling over from one day to the next!! minutesSinceMidnight = minutesSinceMidnight + MINUTES_PER_HOUR; } /* Backs up this time of day by one minute (possibly rolling over into ** the previous day). */ public void goBackwardsByMinute() { // INCORRECT when rolling over from one day to the previous day!! minutesSinceMidnight = minutesSinceMidnight - 1; } /* Backs up this time of day by one hour (possibly rolling over into ** the previous day). */ public void goBackwardsByHour() { // INCORRECT when rolling over from one day to the previous day!! minutesSinceMidnight = minutesSinceMidnight - MINUTES_PER_HOUR; } }