//****************************************************************** // Time.java Author: Torben Hoffmann // Extended by Anne Haxthausen 25/9-2001 // // Representation of the time. //****************************************************************** public class Time { // instance data private int hours, min; // since midnight // constructor public Time(int hours, int min) { // using this to distinguish instance data from // the formal parameters this.hours = hours; this.min = min; } // returns hours since midnight public int gethours() { return hours ;} // returns minutes (over hours) since midnight public int getmin() { return min; } // 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(hours) + "." + twodigits(min); } // s.passtime(min) moves the current time s min minutes forward void passtime(int min) { int totalMin = 60 * this.hours + this.min + min; this.hours = (totalMin/60)%24; this.min = totalMin%60; } // returns a new Time object min minutes into the future public Time plus(int min) { int totalMin = 60 * this.hours + this.min + min; return new Time((totalMin/60)%24, totalMin%60); } // s.to(s) returns the number of minutes from s to t public int to(Time t) { return 60 * t.hours + t.min - 60 * this.hours - this.min; } // s.before(t) returns true if s is earlier in the day than t public boolean before(Time t) { return (this.hours