/* 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 { // instance variables // ------------------ boolean isAM; // true means that the represented time is before noon int hour; int minute; // constructors // ------------ /* Initializes this TimeOfDay object to represent the time of day ** described by the three parameters. ** precondition: 1 <= h <= 12 && 0 <= m < 60 */ public TimeOfDay(int h, int m, boolean isAM) { setTo(h,m,isAM); } /* Initializes this object to represent noon. */ public TimeOfDay() { this(12, 0, false); } // observers // --------- /* Returns a String describing the time of day represented by this object. ** Examples: "7:38AM", "11:06PM" */ public String toString() { if (this.minute >= 10) { if (isAM) { return hour + ":" + minute + "AM"; } else { return hour + ":" + minute + "PM"; } } else { if (isAM) { return hour + ":0" + minute + "AM"; } else { return hour + ":0" + minute + "PM"; } } } /* 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 false; // STUB } // mutators // -------- /* Sets this time of day to that described by the three parameters. ** precondition: 1 <= h <= 12 && 0 <= m < 60 */ public void setTo(int h, int m, boolean isAM) { this.hour = h; this.minute = m; this.isAM = isAM; } /* Advances this time of day by one minute (possibly rolling over into ** the following day). */ public void goForwardByMinute() { minute = minute + 1; if (minute == 60) { minute = 0; hour = hour + 1; if (hour == 13) { hour = 1; } } // This method is flawed!! } /* Advances this time of day by one hour (possibly rolling over into ** the following day). */ public void goForwardByHour() { // STUB } /* Backs up this time of day by one minute (possibly rolling over into ** the previous day). */ public void goBackwardsByMinute() { // STUB } /* Backs up this time of day by one hour (possibly rolling over into ** the previous day). */ public void goBackwardsByHour() { // STUB } }