dimanche 27 juin 2021

Why is my do while loop only happening once? [duplicate]

I wrote a do while loop and there is are if else statements that determine if the loop happens again. The problem is the loop is not happening again when it is supposed to.

    public static void checkGuestOut(Scanner console, String[] guestLog, String guestName) {
        int capsuleNumber;
        boolean availableCapsule = true;
        do {
            System.out.println("Let's get the guest checked out!");
            System.out.print("What is the guest's capsule number? ");
            capsuleNumber = Integer.parseInt(console.nextLine());
            if (guestLog[capsuleNumber-1].equalsIgnoreCase("[unoccupied]")) {
                System.out.println("That room is not occupied.");
                availableCapsule = false;
            }
            else{
                System.out.printf("%s is now checked out of capsule number %s.", guestName, capsuleNumber);
                guestLog[capsuleNumber - 1] = "[unoccupied]";
                availableCapsule = true;
            }
        } while(availableCapsule = false);
    }

Aucun commentaire:

Enregistrer un commentaire