Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.97 KB | None | 0 0
  1. public class ClockDisplay
  2. {
  3.     private NumberDisplay hours;   //private means private to this class(clockdisplay)
  4.     private NumberDisplay minutes;
  5.     private NumberDisplay seconds;
  6.     private String displayString;    // simulates the actual display
  7.    
  8.     public ClockDisplay() //this is constructor
  9.     {
  10.         hours = new NumberDisplay(13);
  11.         minutes = new NumberDisplay(60);
  12.         seconds = new NumberDisplay(0);
  13.         updateDisplay();
  14.     }
  15.  
  16. public void timeTick() // a method
  17.  {    
  18.     int hour;
  19.          
  20.     minutes.increment();
  21.     if(minutes.getValue() == 0) {  // it just rolled over!
  22.     hours.increment();
  23.     hour = hours.getValue() + 1;
  24.    {
  25.     if(hours.getValue() > 12)
  26.          
  27.     hour = hours.getValue() - 12;
  28.     hours.setValue(hour);
  29.    }
  30.     }
  31.     {      
  32.     updateDisplay();
  33.     }
  34.     }  
  35.  
  36. public void timeMode()
  37. {
  38.            if(hours.getValue() == 0 && minutes.getValue() == 0)
  39.            System.out.println("It is currently Midnight");
  40.            if(hours.getValue() == 12 && minutes.getValue() == 0)
  41.            System.out.println("It is currently Noon");
  42.            if(hours.getValue() > 0) {
  43.            System.out.println("It is currently AM");
  44.            if(hours.getValue() > 12)
  45.            System.out.println("It is currently PM");
  46.            }
  47. }
  48.  
  49.     public void setTime(int hour, int minute, int seconds)
  50.     {
  51.         hours.setValue(hour);
  52.         minutes.setValue(minute);
  53.         seconds.setValue(seconds);
  54.         updateDisplay();
  55.     }
  56.  
  57.     /**
  58.      * Return the current time of this display in the format HH:MM.
  59.      */
  60.     public String getTime()
  61.     {
  62.         return displayString;
  63.     }
  64.    
  65.     /**
  66.      * Update the internal string that represents the display.
  67.      */
  68.     private void updateDisplay()
  69.     {
  70.         displayString = hours.getDisplayValue() + ":" + minutes.getDisplayValue() + ":" +
  71.                         seconds.getDisplayValue();      
  72.     }
  73.    
  74.    
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement