
/*===================================================================
 * Write a description of class Clock here.
 * author: Fazli Can
 * version: Clock, April 3, 2002
 * Represents a digital clock with am/pm indicator.
 ====================================================================*/
public class Clock
{
    private
        int hours, minutes, seconds;  // hours: 0 - 23
        String amPm;
    //===============================================================
    // Create a clock and set the initial time as midnight:
    // hours= minutes= seconds= 0, amPm= "am"
    //===============================================================
    public Clock ( )
    {
        hours= minutes= seconds= 0;
        amPm= "am";
    }
    //===============================================================
    // Set hours and amPm information
    //===============================================================
    public void setHours(int inputHours, String inputAmpm)
    {
         hours= inputHours;
         amPm= inputAmpm;
    }
     //===============================================================
    // Set minutes information
    //===============================================================
    public void setMinutes(int inputMinutes)
    {
         seconds= inputMinutes;
    }     
    //===============================================================
    // Set seconds information
    //===============================================================
    public void setSeconds(int inputSeconds)
    {
         seconds= inputSeconds;
    }         
    //===============================================================
    // Tick the clock.
    //===============================================================
    public void tick( )
    {
         int totalSeconds;
         totalSeconds= 3600 * hours + 60 * minutes + seconds + 1;
         hours= totalSeconds / 3600 % 24;
         minutes= totalSeconds % 3600 / 60;
         seconds= totalSeconds % 60;  
         amPm=  (hours < 12)? "am" : "pm";
    }  
   //===============================================================
    // Display the clock.
    //===============================================================
    public void display( )
    {
         String hZero, mZero, sZero;
         hZero= (hours < 10)? "0" : "";
         mZero= (minutes < 10)? "0" : "";
         sZero= (seconds < 10)? "0" : "";
         System.out.println("Time: " + hZero + hours + ":" 
                                     + mZero + minutes + ":" 
                                     + sZero + seconds + " " + amPm);
    }
   //===============================================================
    // Check if the times of two clocks are equal to each other
    //===============================================================
    public boolean equals(Clock otherClock)
    {
         boolean result;
         if(this.hours == otherClock.hours &&
            this.minutes == otherClock.minutes &&
            this.seconds == otherClock.seconds &&
            this.amPm.equals(otherClock.amPm)  )
            result= true;
         else 
            result= false;
         return(result);
    }         
}



