dimanche 15 juillet 2018

Why is it still giving me an error even though I put return types in all of my if/else statements?

Error: This method must return a result of type Outcome

I put return statements in all of my if/else statements, so its not possible that none of them will execute, right? So shouldn't the compiler recognize this?

public Outcome findWinner(Play user, Play computer) {
    if(user == computer) {
        ties++;
        return Outcome.Tie;         
    }

    if(user == Play.ROCK) {
        if (computer == Play.SCISSORS) {
            userWins++;
            userBalance += betAmount;
            return Outcome.userWin;
        }
        compWins++;
        userBalance -= betAmount;
        return Outcome.compWin;
    }

    else if(user == Play.PAPER) {
        if (computer == Play.ROCK) {
            userWins++;
            userBalance += betAmount;
            return Outcome.userWin;
        }
        compWins++;
        userBalance -= betAmount;
        return Outcome.compWin;
    }
    else {
        if (user == Play.SCISSORS) {
            if (computer == Play.PAPER) {
                userWins++;
                userBalance += betAmount;
                return Outcome.userWin;
            }
            compWins++;
            userBalance -= betAmount;
            return Outcome.compWin;
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire