/* An instance of this class represents a time of day, precise to the ** minute (e.g., 7:38am). */ 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) { hour = h; minute = m; this.isAM = 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() { return hour + ":" + minute + isAM; } /* Returns a String describing the time of day represented by this object, ** in the 24-hour format (sometimes referred to as the "military" format) ** (e.g., 15:27, 9:05). */ public String toString24Format() { return ""; // 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) { // STUB } /* Advances this time of day by one minute (possibly rolling over into ** the following day). */ public void goForwardByMinute() { // STUB } /* 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 } // -------------------------------------- // main() (strictly for testing purposes) // -------------------------------------- public static void main(String[] args) { int hr = Integer.parseInt(args[0]); int min = Integer.parseInt(args[1]); boolean isAM = args[2].charAt(0) == 'A'; TimeOfDay tod = new TimeOfDay(hr, min, isAM); System.out.println("Time of day is: " + tod.toString() + " or " + tod.toString24Format()); tod.goForwardByMinute(); System.out.println("After going forward by a minute: " + tod.toString() + " or " + tod.toString24Format()); tod.goBackwardsByMinute(); System.out.println("After going backwards by a minute: " + tod.toString() + " or " + tod.toString24Format()); tod.goForwardByHour(); System.out.println("After going forward by an hour : " + tod.toString() + " or " + tod.toString24Format()); tod.goBackwardsByHour(); System.out.println("After going backwards by an hour: " + tod.toString() + " or " + tod.toString24Format()); } }