
/**
 * 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() {
		String Min1 = new String("");
		if(this.minutes<=9){
			String Min2 = "0"+this.minutes;
			Min1=Min2;
		}
		else{
			String Min3 = new String(String.format("%d",this.minutes));
			Min1=Min3;
		}
		return String.format("%d:%2s %s", this.hours,Min1, 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.minutes=0;
			if(this.hours==12){
				this.hours=1;
			}else{
			this.hours+=1;
			}
				
			
		if(this.hours==11 &&this.minutes==59 && this.meridian=="PM"){
			// if(this.meridian=="PM"){
			this.minutes=0;				
			this.hours+=1;
			this.meridian="AM";
			}
		if(this.hours==11 &&this.minutes==59 && this.meridian=="AM"){
			this.minutes=0;				
			this.hours+=1;	
			this.meridian="PM";
			}
				
			}
	else // MB
		{
		this.minutes+=1;
		}

	

   /**
	 * 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.equals(other){
// throw Exception IllegalArgumentException
// }
// Clock c = new Clock(12, 0, "AM");
// Clock d = new Clock(11, 59, "PM");
// if(this>){
// return 1;
// }
// if(other.clock==this.clock){
		return 0;
// }
	}
}
