
/**
 * 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() {
		
		if(this.minutes<10){
			return this.hours+":"+"0"+this.minutes+" "+this.meridian;
		}
		else
		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!=59&&this.hours!=11){
			this.minutes = this.minutes+1;
		}
		if(this.minutes==59&&this.hours!=11&&this.hours!=12){
			this.hours = this.hours+1;
			this.minutes = 0;
		}
		if(this.minutes==59&&this.hours==11&&this.meridian=="AM"){
			this.hours = this.hours+1;
			this.minutes = 00;
			this.meridian = "PM";
		}
		if(this.minutes==59&&this.hours==11&&this.meridian=="PM"){
			this.hours = this.hours+1;
			this.minutes = 00;
			this.meridian = "AM";
		}
		if(this.minutes==59&&this.hours==12){
			this.hours = 1;
			this.minutes = 0;
		}
			
		
		
	}

   /**
    * Is this time the same as other?
    */
	@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) {
		if(other instanceof Clock == false){
			throw new IllegalArgumentException("");
		}
		int status = 0;
		if(this.hours==((Clock)other).hours&&this.minutes>((Clock)other).minutes){
			status = 1;
		}
		if(this.hours==((Clock)other).hours&&this.minutes<((Clock)other).minutes){
			status = -1;
		}
		return status;
		
	}
}
