Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.50 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(60);
  13.         updateDisplay();
  14.     }
  15.  
  16.       public ClockDisplay(int hour, int minute, int seconds) // this is constructor
  17.     {
  18.         hours = new NumberDisplay(hour);
  19.         minutes = new NumberDisplay(minute);
  20.         seconds = new NumberDisplay(seconds);
  21.         setTime(hour, minute, seconds);
  22.     }
  23.    
  24. public void timeTick() // a method
  25.  {    
  26.     int hour;
  27.          
  28.     minutes.increment();
  29.     if(minutes.getValue() == 0) {  // it just rolled over!
  30.     hours.increment();
  31.     hour = hours.getValue() + 1;
  32.    
  33.     if(hours.getValue() > 12) {
  34.          
  35.     hour = hours.getValue() - 12;
  36.     hours.setValue(hour);
  37.    }
  38.     }
  39.     {      
  40.     updateDisplay();
  41.     }
  42.     }  
  43.  
  44. public void timeTickSeconds()
  45. {
  46.     int minute;
  47.          
  48.     seconds.increment();
  49.     if(seconds.getValue() == 0) {  // it just rolled over!
  50.     minutes.increment();
  51.     minute = minutes.getValue() + 1;}
  52.     {      
  53.     updateDisplay();
  54.     }
  55. }
  56.  
  57. public void timeMode()
  58. {
  59.            if(hours.getValue() == 0 && minutes.getValue() == 0)
  60.            System.out.println("It is currently Midnight");
  61.            if(hours.getValue() == 12 && minutes.getValue() == 0)
  62.            System.out.println("It is currently Noon");
  63.            if(hours.getValue() > 0) {
  64.            System.out.println("It is currently AM");
  65.            if(hours.getValue() > 12)
  66.            System.out.println("It is currently PM");
  67.            }
  68. }
  69.  
  70.     public void setTime(int hour, int minute, int second)
  71.     {
  72.         hours.setValue(hour);
  73.         minutes.setValue(minute);
  74.         seconds.setValue(second);
  75.         updateDisplay();
  76.     }
  77.  
  78.     /**
  79.      * Return the current time of this display in the format HH:MM.
  80.      */
  81.     public String getTime()
  82.     {
  83.         return displayString;
  84.     }
  85.    
  86.     /**
  87.      * Update the internal string that represents the display.
  88.      */
  89.     private void updateDisplay()
  90.     {
  91.         displayString = hours.getDisplayValue() + ":" + minutes.getDisplayValue() + ":" +
  92.                         seconds.getDisplayValue();      
  93.     }
  94.    
  95.    
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement