Question
First to One Game This game is meant for two or more players. In the game, each player starts out with 50 points, as each
First to One Game
This game is meant for two or more players. In the game, each player starts out with 50 points, as each player takes a turn rolling a pair of dice; the amount generated by the dice is subtracted from the player's point. The first player with exactly one point remaining wins. If a player's remaining points minus the amount generated by the dice results in a value less than one, then the amount should be added to the player's points. (As an alternative, the game can be played with a set number turns. In thsi case, the player with the amount of points closest to one, when all rounds have been played, wins.)
Write a program that simulates the game being played by two players. Use the Die class that was presented in Chapter 4 to simulate the dice. Write a player class to simulate the players.
1 import java.util.Random; sides die with a specified number of 4 The Die class simulates a 7 public class Die 9 private int sides; /Number of sides 10 private int valueThe die's value 12 13 14 15 16 The constructor pexforms an initial roll of the die. The number of sides for the die is passed as an argument. 18 public Die (int numSides) 20 sides numSides; 21 roll () 23 24 25 26 27 28 29 -The roll method simulates the rolling of +the die public void rol1() / Create a Random object Random rand new Random) 31 32 // Get a random value for the die. 34 35 36 + 1; value rand.nextInt (sides) 1 import java.util.Random; sides die with a specified number of 4 The Die class simulates a 7 public class Die 9 private int sides; /Number of sides 10 private int valueThe die's value 12 13 14 15 16 The constructor pexforms an initial roll of the die. The number of sides for the die is passed as an argument. 18 public Die (int numSides) 20 sides numSides; 21 roll () 23 24 25 26 27 28 29 -The roll method simulates the rolling of +the die public void rol1() / Create a Random object Random rand new Random) 31 32 // Get a random value for the die. 34 35 36 + 1; value rand.nextInt (sides)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started