Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ClockDisplay
- {
- private NumberDisplay hours; //private means private to this class(clockdisplay)
- private NumberDisplay minutes;
- private NumberDisplay seconds;
- private String displayString; // simulates the actual display
- public ClockDisplay() //this is constructor
- {
- hours = new NumberDisplay(13);
- minutes = new NumberDisplay(60);
- seconds = new NumberDisplay(0);
- updateDisplay();
- }
- public void timeTick() // a method
- {
- 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;
- hours.setValue(hour);
- }
- }
- {
- updateDisplay();
- }
- }
- public void timeMode()
- {
- if(hours.getValue() == 0 && minutes.getValue() == 0)
- System.out.println("It is currently Midnight");
- if(hours.getValue() == 12 && minutes.getValue() == 0)
- System.out.println("It is currently Noon");
- if(hours.getValue() > 0) {
- System.out.println("It is currently AM");
- if(hours.getValue() > 12)
- System.out.println("It is currently PM");
- }
- }
- public void setTime(int hour, int minute, int seconds)
- {
- hours.setValue(hour);
- minutes.setValue(minute);
- seconds.setValue(seconds);
- 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() + ":" +
- seconds.getDisplayValue();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement