public class ClockDisplay { private NumberDisplay hours; // different class private NumberDisplay minutes; //" " private String displayString; // simulates the actual display private boolean turnAlarmOff; private boolean turnAlarmOn; private int alarmHour; private int alarmMinute; /** * Constructor for ClockDisplay objects. This constructor * creates a new clock set at 00:00. */ public ClockDisplay() { hours = new NumberDisplay(24); 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, int alarmH, int alarmM) { hours = new NumberDisplay(24); 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() //cannot get this method to work for setTurnAlarmOn method. { minutes.increment(); if(minutes.getValue() == 0) { // clock "rolls over" 60 sec "tick" hours.increment(); } if(alarmHour == hours.getValue() && alarmMinute == minutes.getValue()){ System.out.println("The alarm is ringing."); } updateDisplay(); } /** * Set the time of the display to the specified hour and * minute. */ 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() { int hour = hours.getValue(); String suffix; if(hour >= 12) { suffix = " pm"; } else { suffix = " am"; } if(hour >= 12) { hour -= 12; } if(hour == 0) { hour = 12; } displayString = hour + ":" + minutes.getDisplayValue() + suffix; } /** * Set the alarm clock time */ public void setTurnAlarmOn(int alarmH, int alarmM) //Would like this alarmMinute to follow the timeTick { int hGood = 0; int hMGood = 0; if(alarmHour == 0){ alarmHour = 12; hGood = 1; } if(alarmHour >= 0 && alarmHour <= 23){ alarmHour = alarmH; hGood = 1; } else { System.out.println("Please input a valid time."); } if(alarmHour >= 13 && alarmHour <=23){ alarmHour -= 12; hGood = 1; } else { System.out.println("Please input a valid time."); } if(alarmMinute >=0 && alarmMinute <= 59) { alarmMinute = alarmM; hMGood = 1; } else{ System.out.println("Please input a valid time."); } if(hGood == 1 && hMGood == 1){ turnAlarmOn = true; } else{ turnAlarmOn = false; } }