Java 如何创建一个菜单系统,允许用户以自己想要的方式运行程序?

Java 如何创建一个菜单系统,允许用户以自己想要的方式运行程序?,java,linked-list,menu,user-input,Java,Linked List,Menu,User Input,我正在尝试这样做,用户可以将员工信息添加到由cvs文件引入的链接列表中。用户可以使用菜单系统以任何方式运行程序。我试图在菜单中创建的代码是发布在我的公共静态void main中的代码 public static void main(String[] args) { Scanner blue = new Scanner(System.in); //variables int run = 0; String choice2

我正在尝试这样做,用户可以将员工信息添加到由cvs文件引入的链接列表中。用户可以使用菜单系统以任何方式运行程序。我试图在菜单中创建的代码是发布在我的公共静态void main中的代码


    public static void main(String[] args) {

        Scanner blue = new Scanner(System.in);

        //variables
        int run = 0;
        String choice2;
        String choice1;
        String IdDel;
        int EmId = 0;
        int Delete;
        String findId;
        int fId = 0;
        char quit = 'n';
        String input;
        int choice = 0;

        //Allow the user to add data
        while (quit != 'q') {
            System.out.println("First Name: ");
            String fName = blue.nextLine();
            System.out.println("Last Name: ");
            String lName = blue.nextLine();
            System.out.println("City: ");
            String city = blue.nextLine();
            System.out.println("State: ");
            String state = blue.nextLine();
            System.out.println("Employee ID: ");
            EmId = Integer.parseInt(blue.nextLine());

            //Add first or last
            System.out.println("Enter this info first or last to the list? f/l");
            choice1 = blue.nextLine().toLowerCase();
            switch (choice1) {
                case "f":
                    theList.insertFirst(fName, lName, city, state, EmId);
                    break;
                case "l":
                    theList.insertLast(fName, lName, city, state, EmId);
                    break;
                default:
                    System.out.println("That was not a choice ");
                    break;
            }
            theList.displayForward();
            
            //Allow the user to delete by employee number
            System.out.println("Would you like to delete an employee? y/n");
            IdDel = blue.nextLine().toLowerCase();
            switch (IdDel) {
                case "y":
                    System.out.println("Enter in the value to delete: ");
                    Delete = Integer.parseInt(blue.nextLine());
                    theList.deleteKey(Delete);
                    break;
                case "n":
                    quit = IdDel.charAt(0);
                    break;
                default:
                    System.out.println("That was not a choice. ");
                    break;
            }
            
            //Allow the user to search by last name
            System.out.println("Would you like to search for an employee? y/n");
            findId = blue.nextLine().toLowerCase();
            switch (findId) {
                case "y":
                    System.out.println("Enter in the ID of the employee you wish to search for: ");
                    theList.findData(fId);
                    break;
                case "n":
                    quit = findId.charAt(0);
                    break;
                default:
                    System.out.println("That was not a choice. ");
                    break;
            }
            //theList.displayForward();
            String thePath = "c:\\z\\data100k.csv";
            readFile(thePath);
            theList.displayForward();
        }
    }
}

这可能是学习java方法的正确时机(通过阅读教程/文档)。然后,下一步是将代码重构为逻辑方法,比如一个添加员工的方法,另一个搜索员工的方法等等。ppp这可能是学习java方法的正确时机(通过阅读教程/文档)。下一步是将代码重构为逻辑方法,比如一个添加员工的方法,另一个搜索员工的方法等等