/** * TimeStamp implements basic time keeping operations. Times are * kept in hours * and minutes only; seconds are not recorded. Hours are recorded in military * time, thus 2:30pm is kept as 14:30. The user should not use am/pm notation * and should enter all hours in 0-23 military format. *

* The TimeStamp objects are intended only to measure differences * during the course of one day (00:00 to 23:59). You should not subtract * or compare differences across day boundaries. *

* @author You * @version 4/10/2006 */ public class TimeStamp { private int hour; private int minute; /** * A constructor to create a new TimeStamp object with * the specified hours and minutes. * @param hr the hours in military format (00-23). * @param mn the minutes (00-60). */ public TimeStamp ( int hr, int mn ) { hour = hr % 24; minute = mn % 60; } /** * A constructor to create a new TimeStamp object * with a time specified as a string. * @param s the input string must be of the form "hh:mm" where * hh is the hours (00-23) in 24hr military form and "mm" is the * minutes (00-60). */ public TimeStamp ( String s ) { int index = s.indexOf(":"); String hourString = s.substring(0,index); String minuteString = s.substring(index+1); hour = Integer.parseInt(hourString) % 24; minute = Integer.parseInt(minuteString) % 60; } /** * A method to compare two TimeStamp objects. * The calling object is compared to the input parameter to generate * the following return values: +1 if calling object is bigger, * 0 if they are the same, -1 if the calling object is smaller. * @param ts the second TimeStamp object to be compared * to the calling object. * @return returns: *