// Arup Guha, 1/26/06, an example of a simple class that defines an object
// to keep time.

public class Time {

    private int hours;  // number of hours in the time object.
    private int minutes; // number of minutes in the time object.

	// A constructor that takes in both the number of hours and minutes for
	// the time object to be constructed. The resulting object is created
	// such that the number of minutes is in between 0 and 59.
    public Time(int h, int m) {
    	int total = 60*h + m;
		hours = total/60;
		minutes = total%60;
    }

    // A constructor that just takes in a single integer representing the
    // total number of minutes for an amount of time.
    public Time(int m) {
		hours = m/60;
		minutes = m%60;
    }

    // Default constructor, sets the time object to 0 hours and minutes.
    public Time() {
		hours = 0;
		minutes = 0;
    }
    
    // Accessor methods

    public int getHours() {
		return hours;
    }
    
    public int getMinutes() {
		return minutes;
    }

	// Mutator methods
	
    public void setHours(int h) {
		hours = h;
    }
    
    public void setMinutes(int m) {
		minutes = m;
    }

    // Returns the number of minutes a Time object is.
    private int totalminutes() {
		return 60*hours + minutes;
    }

	// Returns true if and only if the two time objects represent the
	// exact same amount of time.
    public boolean equals(Time time2) {	
		if (this.totalminutes() == time2.totalminutes())
	    	return true;
		else
	    	return false;
    }

	// Returns true if and only if the current object represents a
	// duration of time longer than time2.
    public boolean greaterthan(Time time2) {
		if (totalminutes() > time2.totalminutes())
	    	return true;
		else
	    	return false;
    }

	// Returns a positive integer if the current object is longer than
	// time2, 0 if they are equal in length, and a negative integer if
	// it is shorter than time2.
    public int compareTo(Time time2) {
		return totalminutes() - time2.totalminutes();
    }

    // Adds the Time of the argument with the object the method is called on
    // together and returns their sum as a Time object.
    public Time addtime(Time time2) {
		int min = totalminutes() + time2.totalminutes();
		Time temp = new Time(min);
		return temp;
    }

    // Returns the difference in Time between the argument and the object
    // the method is called on. A Time object is returned.
    public Time difference(Time time2) {
		int min = Math.abs(totalminutes() - time2.totalminutes());
		Time temp = new Time(min);
		return temp;
    }
    
    
	// Returns a String representation of the current object.
    public String toString() {
		return (hours + " hours and " + minutes + " minutes");
    }
    
}

