I have been writing this program where the user enters a value that stands for a day of the week. It then displays the day of week with the time the alarm will go off in the morning. It then asks the user if they wish to close the program and if no it will then start again. I cannot get it to loop and start again when the user enters "n".
public class alarmClock {
public static void main(String[] args) {
String endProgram = "y";
while (endProgram == "y") {
int weekday = readInt("What day of the week is it");
weekday(weekday);
String endProgram = readString("Do you want to end the program y/n");
}
System.out.print(endProgram);
}
public static String readString(String prompt) {
System.out.println(prompt);
java.util.Scanner keyboard = new java.util.Scanner(System.in);
return keyboard.nextLine();
}
public static int readInt(String prompt) {
System.out.println(prompt);
java.util.Scanner keyboard = new java.util.Scanner(System.in);
return keyboard.nextInt();
}
public static void weekday(int weekday) {
if (weekday == 1) {
System.out.println("On monday the alarm will ring at 7am");
} else if (weekday == 2) {
System.out.println("On tuesday the alarm will ring at 7am");
} else if (weekday == 3) {
System.out.println("On wednesday the alarm will ring at 7am");
} else if (weekday == 4) {
System.out.println("On thursday the alarm will ring at 7am");
} else if (weekday == 5) {
System.out.println("On friday the alarm will ring at 7am");
} else if (weekday == 6) {
System.out.println("On saturay the alarm will ring at 7am");
} else if (weekday == 7) {
System.out.println("On Sunday the alarm will ring at 7am");
}
}
}