// Class Angle is used to store an angle in degrees and minutes, as in "29 // degrees and 35 minutes." public class Angle implements Comparable { private int degrees; private int minutes; // pre: minutes <= 59 and minutes >= 0 and degrees >= 0 // (throws IllegalArgumentException if not true) public Angle(int degrees, int minutes) { if (degrees < 0 || minutes < 0 || minutes >= 60) { throw new IllegalArgumentException(); } this.degrees = degrees; this.minutes = minutes; } // post: returns a String representation of this angle as in "29d 35m" public String toString() { return degrees + "d " + minutes + "m"; } // post: returns a new angle that represents the sum of this angle and the // given angle public Angle add(Angle other) { int d = other.degrees + this.degrees; int m = other.minutes + this.minutes; if (m >= 60) { m -= 60; d += 1; } return new Angle(d, m); } // post: returns a negative if this angle less than the other, 0 if this // angle equals the other, a positive if this angle greater than the // other (ordered by degrees first, then by minutes) public int compareTo(Angle other) { if (this.degrees == other.degrees) { return this.minutes - other.minutes; } else { return this.degrees - other.degrees; } } }