Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Let's play a game, use objects, looping constructs and ArrayLists (see bonus) In this project, you will write a craps dice program. (History, from Wikipedia:

Let's play a game, use objects, looping constructs and ArrayLists (see bonus)
In this project, you will write a "craps" dice program. (History, from Wikipedia: Craps developed from a simplification of the Old English game hazard. Its origins are complex and may date to the Crusades, later being influenced by French gamblers. What was to become the modern American version of the game was brought to New Orleans by Bernard Xavier Philippe de Marigny de Mandeville, scion of wealthy Louisiana landowners, a gambler, and politician.)
READ the requirements carefully. ASK ME if you are not sure of something.
Game Rules:
First, you will need to know the rules of the game:
1.
The player roles two six-sided die, with a resulting score between 1-6, and a sum between 2-12. On this initial role, if the score sum is 2, 3, or 12, the player loses (this is known as "crap out").
2.
If on that initial roll the sum of the dice is 7 or 11, the player wins (this is known as a "natural").
3.
For any other score (4, 5, 6, 8, 9, 10), the number is remembered (also known as "established") and the dice are re-rolled until either:
a.
A sum of seven is rolled (in which case the player loses -this is called "seven out".
b.
The initial number is achieved (in which case the player wins).
Your program should do the following:

Prompt the user to enter their name - this name should be used in messages to the player.

Simulate the initial rolling of the dice by use of a random number generator (see hints below) and determine if the player wins or loses or needs to continue rolling. Put out an appropriate message that includes the players name, the dice values and total, and win/loss/continue rolling status.

Continue to simulate rolling until the player wins or loses. For each of these rolls, put out an appropriate status message (with the players name, dice values and total and win/loss/continue rolling status).

Use objects to represent the Dice. IMPORTANT: Your Dice (Die, since the class should represent a single Die?) class needs to have an instance (object) for each of the two dice. Do not have the class represent the set (two) of Dice. WHY? Because
we want our D
ice/Die class to be reusable for other games, for example Yahtzee which have a different number of Dice.

The Die value must be kept as a private field, and you need to use an Accessor method to get its value. You can have a method to set it (optional), but you must have a public roll method to set its value to a random value.

Keep track of the number of rolls of each die AND overall, for all of the Dice. This must be kept within the Die class.

The Die class should have a constructor to set the number of sides (again, to allow it to be used for other Dice like games, including games that have Die with a different number of sides). Your main/game class should use this constructor to instantiate the Die. You can have the default constructor default the number of sides to 6.

In addition to the program, create a UML diagram for you Die class (as well as other classes you create). Provide this as a pdf.


Bonus points:

b)
1 bonus point if you use dialog boxes for all input and the final win/lose output.
c)
1 bonus point if your program randomly puts out one of the following messages when the player wins:
a.
Hey, (player name here) you're a winner!
b.
Way to go (player name here), you've won!
c.
Yeah (player name here), whatever, so you've won.
and randomly puts out one of the following messages when the player loses:
d.
(player name here) LOSER!
e.
Sorry (player name here), you've lost.
f.
Well (player name here), sometimes you win and sometimes you lose. I win and you LOST!
d)
2 bonus points if your program keeps track of the values rolled for each Die, within the Die object (i.e. as an instance variable). Your program should make use of an
Arraylist (and use a wrapper
class) to hold the variable number of roll values for the Die, and should provide a replay method that allows a caller to get each of the Die's values, e.g. mydie.replay(1) would get the first value that the Die had. (You can make this zero based if you desire, i.e. mydie.replay(0) would get the first value.) Your program should make use of this to "play back" the Die values at the end of the game.
e)
2 bonus points for programs that allow a "simulation mode". When specified, your program should prompt for the number of iterations and then simulate the playing of the game for that number of iterations. The simulation should keep track of (and output when complete) the number of wins, number of losses, longest winning streak, longest losing streak. Your simulation mode should NOT output each of the roll values, just produce the summary data listed here.
Hints:

Random Number Generator:
o
A Random number generator class can be included in your program by the java.util.Random package.
o
To create a random number generator object, you instantiate one via a statement such as:

Random generator = new Random(); // use the random # generator class
o
To obtain a random number, you can use the nextInt() method in the Random class to get a number. nextInt() expects to know the range of numbers, between 0-n. For example, the following call obtains integers between 1 and 10:

int die1 = generator.nextInt(10) + 1;// get a random # between 1 and 10
o
IMPORTANT: You only need ONE call to new up a Random # generator (regardless of the number of rolls of the dice and regardless of the number of dice. Thus, the random number instance (e.g. "generator" in the above) can be a static field in the Die class.
Reminders: Points are taken off for non-commented code! Each person needs to do their own work.


Step by Step Solution

3.39 Rating (155 Votes )

There are 3 Steps involved in it

Step: 1

Heres a Java program that simulates the game of craps according to the provided requirements The program uses classes for Dice and allows you to play the game Additionally it includes the bonus featur... 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

Introduction to Operations Research

Authors: Frederick S. Hillier, Gerald J. Lieberman

10th edition

978-0072535105, 72535105, 978-1259162985

More Books

Students also viewed these Programming questions

Question

Describe major criticisms of Freuds system of thought.

Answered: 1 week ago