// Implements a a second in time that occurs on January 1, 1753 or later. // The invariant is maintained that the moment is a legitimate hour, minute, // second on a legitimate date, expressed in AM/PM format, or else an // illegitimate moment of where the month, day, year, minute, second // are all 0, PM is false, and hour is 12 public interface MomentInterface extends DateInterface, Comparable { // getters int getHour(); int getHourMilitary(); // hour in military time (0-23) int getMinute(); // 0-59 int getSecond(); // 0-59 boolean getPM(); // false if A.M., true if P.M. // preconditions: none // postcondition: true has been returned if the moment is a legitimate // one, and false otherwise boolean isLegal(); // precondition: none // postcondition: an exception has been thrown if either of the moments // is an illegitimate one; otherwise, it returns the number of // seconds from 'this' to m2. This value is negative if // m2 is before 'this'. int secondsUntil(MomentInterface m2); // precondition: none // postcondition: an exception has been thrown if either of the moments // is an illegitimate one; otherwise, it returns the number of // minutes from the moment to m2, *rounded to the nearest minute* // (half a minute rounds up if the result is positive, and down if // the result is negative) int minutesUntil(MomentInterface m2); // precondition: none // postcondition: an exception has been thrown if either of the moments // is an illegitimate one; otherwise, it returns the number of // hours from the moment to m2, *rounded to the nearest hour* // (half an hour rounds up if the result is positive, and down if // the result is negative) int hoursUntil(MomentInterface m2); // precondition: o2 is of a type that implements MomentInterface // postcondition: returns -1 if 'this' is before o2, 0 if they are the // same, 1 if 'this' is after o2. Throws an exception, prints the // stack trace and halts if one of the two is an illegal moment. The // error should indicate whether 'this' or the parameter caused the // exception. int compareTo(Object o2); // Precondition: none // Outputs string in the format m/d/y hour:min:sec AM/PM // Example: 2/26/2012 10:36 AM; 0/0/0 12:0:0 AM String toString(); // In addition, an implementation should have a default constructor // that returns 0/0/0 12:0:0 AM. It should have a constructor // that takes (month, day, year, hour (American format), minute, second, // boolean PM). It should have a copy constructor that takes // a MomentInterface object as a parameter and creates a copy // of the moment as an object in the class that implements it. }