Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ClockDisplay
- {
- private NumberDisplay hours;
- private NumberDisplay minutes;
- private String displayString; // simulates the actual display
- /**
- * Constructor for ClockDisplay objects. This constructor
- * creates a new clock set at 00:00.
- */
- public ClockDisplay()
- {
- hours = new NumberDisplay(13);
- minutes = new NumberDisplay(60);
- updateDisplay();
- }
- /**
- * Constructor for ClockDisplay objects. This constructor
- * creates a new clock set at the time specified by the
- * parameters.
- */
- public ClockDisplay(int hour, int minute)
- {
- hours = new NumberDisplay(13);
- minutes = new NumberDisplay(60);
- setTime(hour, minute);
- }
- /**
- * This method should get called once every minute - it makes
- * the clock display go one minute forward.
- */
- public void timeTick()
- {
- int hour;
- minutes.increment();
- if(minutes.getValue() == 0) { // it just rolled over!
- hours.increment();
- hour = hours.getValue() + 1;
- {
- if(hours.getValue() > 12)
- hour = hours.getValue() - 12;
- }
- }
- {
- updateDisplay();
- }
- }
- public void timeMode()
- {
- int hours = 0; //initializing = setting a value
- int minutes = 0;
- if(hours ==0 && minutes == 0){
- System.out.println("It is currently Midnight");
- if(hours == 12 && minutes == 0)
- System.out.println("It is currently Noon");
- if(hours > 0) {
- System.out.println("It is currently AM");
- if(hours > 12)
- System.out.println("It is currently PM");
- }
- }
- }
- public void setTime(int hour, int minute)
- {
- hours.setValue(hour);
- minutes.setValue(minute);
- updateDisplay();
- }
- /**
- * Return the current time of this display in the format HH:MM.
- */
- public String getTime()
- {
- return displayString;
- }
- /**
- * Update the internal string that represents the display.
- */
- private void updateDisplay()
- {
- displayString = hours.getDisplayValue() + ":" +
- minutes.getDisplayValue();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement