//****************************************************************** // Time.java Author: Torben Hoffmann // Modified by Anne Haxthausen 25/9-2001 // Modified by Morten Proschowsky 1/10-2001 // Modified by Anders Keldsen 14/10-2002 // Representation of the time. //****************************************************************** public class Time { // instance data private int min; // since midnight // constructor public Time(int hours, int min) { // using "this" to distinguish instance data from // the formal parameters this.min = (hours*60+min)%1440; } // returns hours since midnight public int gethours() { return min/60 ;} // returns minutes (over hours) since midnight public int getmin() { return min%60; } // aux method to aid pretty printing of the time, eg, // 09.03 instead of 9.3 private static String twodigits(int n) { // first the tens and then the ones return Integer.toString(n/10) + Integer.toString(n%10); } public String toString() { return twodigits(gethours()) + "." + twodigits(getmin()); } // s.passtime(min) moves the current time min minutes forward void passtime(int min) { this.min = (this.min+min)%1440; } // returns a new Time object, min minutes into the future public Time plus(int min) { int totalMin = (this.min+min)%1440; return new Time(totalMin/60, totalMin%60); } // s.to(t) returns the number of minutes from s to t public int to(Time t) { return t.min - this.min; } // s.before(t) returns true if s is earlier in the day than t public boolean before(Time t) { return (this.min