
/**
 * A 12-hour (non-military time) digital clock.
 *
 * @author Matt Boutell.
 *         Created Mar 27, 2008.
 */
public class Clock implements Comparable {
	// You can use an alternate fields, as long as you update .equals()
	private int hours;
	private int minutes;
	private String meridian; // AM or PM

	/**
	 * Constructs a clock with the given time. You may assume
	 * that the parameters are all in the valid ranges.
	 *
	 * @param hours
	 * @param minutes
	 * @param meridian AM or PM
	 */
	public Clock(int hours, int minutes, String meridian) {
		this.hours = hours;
		this.minutes = minutes;
		this.meridian = meridian;
	}
	
	/** 
	 * Examples: 4:55 PM, 12:03 AM. Note that the hours may be 1 digit,
	 * the minutes must be 2 digits, and there's a space before the meridian,
	 * and no other spaces. 
	 */
	@Override
	public String toString() {
		// TODO: Write this method. (Change the return type I gave you.)
		return this.hours + ":" + this.minutes + this.meridian;
	}
	
	/**
	 * Advances the clock's time by one minute. I know, that's a big TICK!
	 */
	public void tick() {
		if(this.minutes < 60) {
			this.minutes++;
		} else {
			this.minutes = 0;
			this.hours++;
		}
	}

   /**
    * Is this time the same as other?
 * @param other 
 * @return 
 * @throws IllegalArgumentException 
    */
	@Override
	public boolean equals(Object other) {

		Clock rhs = (Clock)other;
		return (this.hours == rhs.hours
		&& this.minutes == rhs.minutes
		&& this.meridian == rhs.meridian);
	}

	/**
	 * Compares two times within a given day. Midnight is the earliest time in a day.
     * Hint: a well-chosen helper function could make your life much easier here!<br>
     * 
	 * Returns -1 if this time is before the other.<br>
	 * Returns  0 if the times are equal.<br>
	 * Returns 1 if this time is after the other.<br>
	 * 
	 * Throw an IllegalArgumentException if other isn't a Clock.
	 */
	@Override
	public int compareTo(Object other)  throws IllegalArgumentException {
		if(other instanceof Clock == false) {
			throw new IllegalArgumentException();
		}
//		if (this.meridian = "AM" && ((Clock)other.meridian) = "PM" || this.hours < ((Clock)other).hours || this.hours >= ((Clock)other).hours && this.minutes < ((Clock)other).minutes) {
//			return -1;
//		}
		return 0;
	}
}
