Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this project, you will write a “craps” dice program. (History, from Wikipedia

ID: 3666387 • Letter: I

Question

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.) First, you will need to know the rules of the game:

The player roles two dice, with a resulting score between 2-12. On this initial role, if the score is 2, 3, or 12, the player loses.

If the sum of the dice are 7 or 11, the player wins.

For any other score (4, 5, 6, 8, 9, 10), the number is remembered and the player must continue rolling the dice until either

A sum of seven is rolled (in which case the player loses).

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 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.   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.

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

Hints:

Random Number Generator:

A Random number generator class can be included in your program by the java.util.Random package.

To create a random number generator object, you instantiate one via a statement such as:

Random generator = new Random();     // use the random # generator class

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

Explanation / Answer

import java.util.Scanner;
import java.util.Random;
public class Craps
{
public static void main(String [] args)
{
int point, sum;
Random randomNumbers = new Random();
Scanner keyboard = new Scanner(System.in);
System.out.println("First roll. ");
sum = roleDice(randomNumbers);
System.out.println("Sum: " + sum + " ");
switch (sum)
{
case 7: case 11:
System.out.println("Player wins.");
break;
case 2: case 3: case 12:
System.out.println("Player loses.");
break;
default:
point = sum;
do
{
sum = roleDice(randomNumbers);
System.out.println("Sum: " + sum + " ");
}
while (sum != 7 && sum != point);
if (sum == point)
System.out.println("Player wins.");
else
System.out.println("Player loses.");
}
}
public static int roleDice(Random randomNumbers)
{
int dice1, dice2;

dice1 = randomNumbers.nextInt(7);
dice2 = randomNumbers.nextInt(7);
System.out.println("Dice 1: " + ++dice1);
System.out.println("Dice 2: " + ++dice2);
return dice1 + dice2;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote