Hello guys! I'm working a project and it seems that there's something wrong with my switch-case. For example, in the user menu, the user can input the number 2 then it would allow them to deposit, but somehow, it keeps displaying the first switch-case.

            case 1: 
            case 2: users.get(0).depositMoney();

            default: System.out.println("Incorrect input!");    

        public int displayUserMenu(ArrayList<User> users){

            Scanner sc = new Scanner(System.in);
            System.out.println("1. Edit Profile");
            System.out.println("2. Deposit Money");
            System.out.println("3. Buy Product");
            System.out.println("4. Remove Product");
            System.out.println("5. Check-out Cart");    
            System.out.print("Input: ");
            int resp = sc.nextInt();

            return resp;

Recommended Answers

All 2 Replies

Please post a compilable and runnable piece of code that reproduces your problem.

might be something wrong in your logic.
the resp variable in your switch statement is not related to the resp variable in your displayUserMenu method.

probably, you are not setting the value of the first variable right.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.