samedi 16 février 2019

My boolean variable could not be resolved into a variable in my while statement

I want to make a code that repeats itself until the user types the word Game or the word Balance. I made a do while loop but I'm getting an error with my while statement. The error is: error3 cannot be resolved into a variable. Does anyone know what the problem of my code is?

    System.out.println("welcome to Roll the Dice!");
    System.out.println("What is your name?");

    Scanner input = new Scanner(System.in);
    String Name = input.nextLine();

    System.out.println("Welcome " + Name + "!" );
    System.out.println("Do you want to play a game or do you want to check your account's balance?");
    System.out.println("For the game typ: Game. For you accounts balance typ: Balance");

    do {
        String Choice = input.nextLine();
        String Balance = "Balance";
        String Game = "Game";
        input.close();

        boolean error1 = ! new String(Choice).equals(Game);
        boolean error2 = ! new String(Choice).equals(Balance);
        boolean error3 = (error2 || error1) == true; 

        if (new String(Choice).equals(Game)){
            System.out.println("Start the game!");
        }

        else if(new String(Choice).equals(Balance)){
            System.out.println("Check the balance");
        }

        else{
            System.out.println("This is not an correct answer");
            System.out.println("Typ: Game to start a game. Typ: Balance to see your account's balance");
            }
    } 
    while(error3 == true);

Aucun commentaire:

Enregistrer un commentaire