Answer to Question #279968 in Java | JSP | JSF for hab1b1ti

Question #279968


If they choose not to roll again (but their most recent roll was not a zero), add



their round score to their total score using



addPoints()


.



G.



Use



getPoints()



to see if the player’s total is greater than or equal to the stored



victory



number.



If



so,



print



out



that



the



player



won



and



call



addWin()


,



then



return;



to end the round. If not, go on to the next player.



1
Expert's answer
2021-12-16T04:50:22-0500
import java.util.Random;

public class Main {
    public static int victory = 100;

    public static void main(String[] args) {
        Player[] players = new Player[2] {
            new Player(), new Player()
        } ;
        Random random = new Random();
        int cur = 0;
        int roll = 0;
        while (true) {
            if (random.nextBoolean()) {
                roll = random.nextInt(10) + 1;
            } else {
                if (roll > 0) {
                    players[cur].addPoints(roll);
                }
                if (players[cur].getPoints() >= victory) {
                    System.out.println("Player " + players[cur].getName() + " win.");
                    players[cur].addWin();
                    return;
                }
                roll = 0;
                cur = (cur + 1) % 2;
            }
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog