vendredi 26 janvier 2018

Conditional statement in Java - Specific approach

How to write a conditional statement for the next purpose:

An app for Android who count the score (dart sport), we implemented 4 methods (add 1p, add 5p, add 10p and add 20p) for player 1.

Inside the method - displayForPlayerOne I wrote an if statement:

public void displayForPlayerOne(int score) {
        if (scorePlayerOne <= 180) {
            TextView scoreView = findViewById(R.id.player_one_score);
            scoreView.setText(String.valueOf(score));
    }else{
     Toast.makeText(this, "You cannot obtain more than 180 points!", Toast.LENGTH_SHORT).show();

When the player 1 has already a score of 175p and the user clicks to add 20p more, the app activates the Toast message, which is fine, after, user want to add 1p or 5p and He can't do this because of the compiler which stopped to the second condition (else).

What solution could I have here?

PS: Thx!

Aucun commentaire:

Enregistrer un commentaire