Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions

Question

5. Design an uncluttered and easy to read survey.

Answered: 1 week ago

Question

3. You can gain power by making others feel important.

Answered: 1 week ago