D
D
Denis Kuznetsov2019-04-02 12:15:20
Java
Denis Kuznetsov, 2019-04-02 12:15:20

Why isn't the loop ending?

There is enam

public enum OutCome {
    BLACKJACK, GAMEOVER, CONTINUE;
}

class Person in which the method
@Override
    public OutCome checkCost(String correction){
        if(cost == 21){
            System.out.println(blackJack);
            return OutCome.BLACKJACK;
        }else if(cost > 21){
            System.out.println(sadMessage);
            return OutCome.GAMEOVER;
        }else{
            System.out.println(correction + messageForChecker + cost);
            return OutCome.CONTINUE;
        }
    }

where cost is an int variable that accumulates map values ​​and objects in sout are just constant strings
and there is a main method in which it is executed
OutCome cost = player.checkCost();
      Scanner scanner = new Scanner(System.in);
      String action = scanner.nextLine();
while ( (!action.equals(enough)) || (cost.equals(OutCome.CONTINUE))){
            player.getAnotherCard(deck); //берет карту
            player.checkLastCard();  // выводит ее пользователю 
           
            cost = player.checkCost(); //переопределяет флаг
// и по новой 
            System.out.println(message);
            action = scanner.nextLine();
        }

but the loop doesn't end

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
EVGENY T., 2019-04-02
@DennisKingsman

while || with && replace

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question