0

I made a program to show options in menu when you select a number.The menu should be displayed after execution of each option prompting the user to enter value for one of the options. The program should end only when the valid entry for exiting the program is provided by the user. The program execute the menu, but how I can display each option, when you enter value for one of the options?


import java.util.Scanner;

public class menu {

    private static String options;

    public static void main(String[] args) {
        System.out.println("Choose from the Menu");
        System.out.println("-------------------------\n");
        System.out.println("1 - Create class list");
        System.out.println("2 - Provide marks for a subject");
        System.out.println("3 - Get grade statistics for a subject");
        System.out.println("4 - Exit");

        options = null;
        try (Scanner scan = new Scanner(System.in)) { // Capturing the input
            do {
                options = scan.nextLine();
                switch (options) {

                case "1":
                    // Perform "Create class list" case.

                    break;

                case "2":
                    // Perform "Provide marks for a subject" case.

                    break;

                case "3":
                    // Perform "Get grade statistics for a subject" case.

                    break;

                case "4":
                    // Perform "Exit" case.

                    break;

                }
            } while (options != "4"); // If no options Exit
        }

    }
}
Ninch
  • 1
  • 1
  • 1
    `options != "4"` - that is not how you compare strings [see here](https://stackoverflow.com/q/513832/2670892) – greg-449 Dec 14 '22 at 13:58

0 Answers0