Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.32 KB | None | 0 0
  1. public class ClockDisplay
  2. {
  3.     private NumberDisplay hours;
  4.     private NumberDisplay minutes;
  5.     private String displayString;    // simulates the actual display
  6.    
  7.     /**
  8.      * Constructor for ClockDisplay objects. This constructor
  9.      * creates a new clock set at 00:00.
  10.      */
  11.     public ClockDisplay()
  12.     {
  13.         hours = new NumberDisplay(13);
  14.         minutes = new NumberDisplay(60);
  15.         updateDisplay();
  16.     }
  17.  
  18.     /**
  19.      * Constructor for ClockDisplay objects. This constructor
  20.      * creates a new clock set at the time specified by the
  21.      * parameters.
  22.      */
  23.     public ClockDisplay(int hour, int minute)
  24.     {
  25.         hours = new NumberDisplay(13);
  26.         minutes = new NumberDisplay(60);
  27.         setTime(hour, minute);
  28.     }
  29.  
  30.     /**
  31.      * This method should get called once every minute - it makes
  32.      * the clock display go one minute forward.
  33.      */
  34. public void timeTick()
  35.  {    
  36.     int hour;
  37.          
  38.     minutes.increment();
  39.     if(minutes.getValue() == 0) {  // it just rolled over!
  40.     hours.increment();
  41.     hour = hours.getValue() + 1;
  42.    {
  43.     if(hours.getValue() > 12)
  44.          
  45.     hour = hours.getValue() - 12;
  46.    }
  47.     }
  48.     {      
  49.     updateDisplay();
  50.     }
  51.     }  
  52.  
  53. public void timeMode()
  54. {
  55.            int hours = 0;  //initializing = setting a value
  56.            int minutes = 0;
  57.            if(hours ==0 && minutes == 0){
  58.            System.out.println("It is currently Midnight");
  59.            if(hours == 12 && minutes == 0)
  60.            System.out.println("It is currently Noon");
  61.            if(hours > 0) {
  62.            System.out.println("It is currently AM");
  63.            if(hours > 12)
  64.            System.out.println("It is currently PM");
  65.            }
  66.            }
  67. }
  68.  
  69.     public void setTime(int hour, int minute)
  70.     {
  71.         hours.setValue(hour);
  72.         minutes.setValue(minute);
  73.         updateDisplay();
  74.     }
  75.  
  76.     /**
  77.      * Return the current time of this display in the format HH:MM.
  78.      */
  79.     public String getTime()
  80.     {
  81.         return displayString;
  82.     }
  83.    
  84.     /**
  85.      * Update the internal string that represents the display.
  86.      */
  87.     private void updateDisplay()
  88.     {
  89.         displayString = hours.getDisplayValue() + ":" +
  90.                         minutes.getDisplayValue();
  91.     }
  92.    
  93.    
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement