Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN JAVA: This game is meant for two or more players., Each player starts out with 50 points, as each player takes a turn rolling

IN JAVA: This game is meant for two or more players., Each player starts out with 50 points, as each player takes a turn rolling the dice; the amount generated by the dice is subtracted from the players points. The first player with exactly one point remaining wins. If a players remaining points minus the amount generated by the dice results in a value less than one, then the amount should be added to the players points. (As a alternative, the game can be played with a set number of turns. In this 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 6 to simulate the dice. Write a Player class to simulate the player. Enter the players names and display the die rolls and the totals after each round.

THIS IS THE DIE CLASS: please complete entire program and upload screenshot of output along with the answer.

import java.util.Random;

/** The Die class simulates a six-sided die. */

public class Die { private int sides; // Number of sides private int value; // The die's value /** The constructor performs an initial roll of the die. @param numSides The number of sides for this die. */ public Die(int numSides) { sides = numSides; roll(); } /** The roll method simlates the rolling of the die. */ public void roll() { // Create a Random object. Random rand = new Random(); // Get a random value for the die. value = rand.nextInt(sides) + 1; } /** getSides method @return The number of sides for this die. */ public int getSides() { return sides; } /** getValue method @return The value of the die. */ public int getValue() { return value; } }

OUTPUT SHOULD BE SOMETHING LIKE:

---------------------------------

Round 1:

player1 rolled a 6

player2 rolled a 4

player1 has 44 points

player2 has 46 points

player1 wins.

----------------------------------

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

Database Systems A Practical Approach To Design Implementation And Management

Authors: THOMAS CONNOLLY

6th Edition

9353438918, 978-9353438913

More Books

Students also viewed these Databases questions

Question

Sketch a graph of the equation. x = 4

Answered: 1 week ago

Question

Explain the theoretical issues surrounding the HRM debate

Answered: 1 week ago

Question

1. Identify outcomes (e.g., quality, accidents).

Answered: 1 week ago