Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A simple digital alarm clock has a display, showing “hour:minute”, and four butt

ID: 3762152 • Letter: A

Question

A simple digital alarm clock has a display, showing “hour:minute”, and four buttons marked "Clock Set", "Alarm Set", "+", and "-". Normally the display shows the time. By pressing "Clock Set" the display shows the time but allows setting the clock by pressing "+" or "-" to increase or decrease the hour. Pressing "Clock Set" second time allows the changing the minutes, and pressing the third time returns the display to showing the time.
By pressing "Alarm Set" the display shows the alarm time and allows setting the alarm hour by pressing "+" or "-" to increase or decrease the hour. Pressing "Alarm Set" second time allows the changing the minutes, and pressing the third time returns the display to showing the time. That is the alarm clock can be in one of the five states: "display time", "set Clock hour", "set Clock minute", "set Alarm hour", and "set alarm minute".


The hardware buttons of the clock invoke methods in the AlarmClock interface

Implement your production code and test suit.

public interface AlarmClock {
/** return the contents of the display depending on the
* state of the alarm clock.yy
* @return the display contents
*/
public String readDisplay();

/** press the "AlarmSet" button on the clock */
public void AlarmSet();

/** press the "ClockSet" button on the clock */
public void ClockSet();

/** press the "increase" (+) button on the clock */
public void increase();

/** press the "decrease" (-) button on the clock */
public void decrease();
}

Explanation / Answer

package alarm;
import java.util.Scanner;


public class Alarm {
    static int id; // increment decrement
    static int chr, cmin, ahr, amin;
    static Scanner sc = new Scanner(System.in);
    static String alarmState;
    static void dispTm(){
        System.out.println(alarmState);
      
      
      
    }
  
    static void setClkHr() {
   System.out.println(alarmState);
    id = sc.nextInt();
    if ( id == 1) chr++;
    if ( id == 0 ) chr--;
  
    System.out.println(" Hour: " + chr);

    }
  
    static void setClkMn() {
      System.out.println(alarmState);
      id = sc.nextInt();
      if ( id == 1) cmin ++;
      if ( id == 0 ) cmin --;
    
      System.out.println(" Minutes: " + cmin);
    
    }
  
    static void setAlHr() {
        System.out.println(alarmState);
        id = sc.nextInt();
        if ( id == 1) ahr ++;
        if ( id == 0 ) ahr --;
      
        System.out.println(" Hour: " + ahr);
      
    }
  
    static void setAlMn() {
        System.out.println(alarmState);
        id = sc.nextInt();
        if ( id == 1 ) amin ++ ;
        if ( id == 0 ) amin --;
      
                System.out.println(" Mnutes: " + amin);
      
      
    }
    public static void main(String[] args) {

  
  
    alarmState = " Display Time";
    dispTm();
    alarmState = " Set Clock Hour";
    setClkHr();
    alarmState = " Set Clock Minute";
    setClkMn();
    alarmState = " Set Alarm Hour ";
    setAlHr();
    alarmState = " Set Alarm Minute ";
    setAlMn();
  
    }
  
}

run:
Display Time
Set Clock Hour
1
Hour: 1
Set Clock Minute
1
Minutes: 1
Set Alarm Hour
1
Hour: 1
Set Alarm Minute
1
Mnutes: 1
BUILD SUCCESSFUL (total time: 5 seconds)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote