title: Java Clock Assignment
body: <p>For my assignment we are suppose to make a clock. We need variables of hours, minutes, and seconds and methods like setHours/getHours, setMinutes/getMinutes, setSeconds/getSeconds. I also need a addClock() method to make the sum of two clock objects and a tickDown() method which decrements the clock. Also I need a tick() method that increments a Clock object by one second. </p>
  
  <p>Here is what I have so far... </p>
  
  <pre><code>public class Clock {
  
     private int hr; //store hours
     private int min; //store minutes
     private int sec; //store seconds
  
     // Default constructor
  
     public Clock () {
        setClock (0, 0, 0);
     }
  
     public Clock (int hours, int minutes, int seconds) {
        setClock (hours, minutes, seconds);
     }
  
     public void setClock (int hours, int minutes, int seconds) {
        if (0 &lt;= hours &amp;&amp; hours &lt; 24)
           hr = hours;
        else
           hr = 0;
        if (0 &lt;= minutes &amp;&amp; minutes &lt; 60)
           min = minutes;
        else
           min = 0;
        if (0 &lt;= seconds &amp;&amp; seconds &lt; 60)
           sec = seconds;
        else
           sec = 0;
     }
  
     public int getHours() {
        return hr;
     }
  
     public int getMinutes() {
        return min;
     }
  
     public int getSeconds() {
        return sec;
     }
  
     public void addClock( Clock secondClock ) {
        this.sec += secondClock.getSeconds();
        this.min += secondClock.getMinutes();
        //add overflow to minutes from seconds
        this.min +=(int)(this.sec/60);
        //update seconds 
        this.sec = this.sec % 60;
        this.hr += secondClock.getHours();
        //add overflow to minutes from seconds
        this.hr +=(int)(this.min/60);
        //update minutes
        this.min = this.min % 60;
        //adjust hours
        this.hr = this.hr % 24;
     }
  
     public void tick(){
        this.sec += 1;
        //add overflow to minutes from seconds
        this.min +=(int)(this.sec/60);
        //update seconds 
        this.sec = this.sec % 60;
        //add overflow to minutes from seconds
        this.hr +=(int)(this.min/60);
        //update minutes
        this.min = this.min % 60;
        //adjust hours
        this.hr = this.hr %24;
     }
  
     public void tickDown(){
        this.sec -= 1;
        if(this.sec &lt;0){
           this.sec+=60;
           this.min-=1;
        }
        if(this.min&lt;0){
           this.min+=60;
           this.hr-=1;
        }
        if(this.hr&lt;0){
           this.hr+=24;
        }
     }
  }
  </code></pre>