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

The game of craps uses two 6-sided dice, where each die contains a number betwee

ID: 3637479 • Letter: T

Question

The game of craps uses two 6-sided dice, where each die contains a number between 1 and 6.
The total of the two sides that face up is the total for a roll of the dice. (meaning if the dice are
rolled and one die has 3 facing up and the other has 5 facing up the total is 8)
The first roll that a player throws has three possible outcomes: they can win, they can lose, or
they will continue to roll.
On the first roll, if the player gets a 7 or 11 that is a win.
On the first roll, if the player gets a 2, 3, or 12 that is a loss.
On the first roll, if the player gets anything else (4,5,6,8,9,10) then that is their mark and they
need to continue to roll trying to get that mark.

Lab:
Simulate 100,000,000 (100 million) “first rolls” of the dice and count the number of Wins,
Losses, and Marks. After the simulated rolls, report on the number and percentage of each.
Sample (numbers redacted):
Wins: ##,###,### ##.#%
Losses: ##,###,### ##.#%
Marks: ##,###,### ##.#%
Press any key to continue . . .
Hints: use a loop for the 100 million rolls – inside the loop generate random numbers for the
two dice and based on the roll, increment the appropriate counters. After the loop, show the
counts and percentages.

Explanation / Answer

static Random generator = new Random(); int die1, die2, total, markGoal; int wins = 0, losses = 0, mark = 0; for (int i = 0; i < 100,000,000; i++){ die1 = generator.nextInt(6) + 1; die2 = generator.nextInt(6) + 1; total = die1 + die2; if (total == 7 || total == 11) wins += 1; else if (total == 2 || total == 3 || total == 12) losses += 1; else if (i == 0) mark += total; } System.out.println("Sample:"); System.out.println("Wins: " + wins +" " + wins/1000000 + "%"); System.out.println("Losses: " + losses +" " + losses/1000000 + "%"); System.out.println("Marks: " + mark +" " + mark/1000000 + "%"); System.out.println("Press any key to continue . . ."); //Not sure what you meant by the "that is their mark and they need to continue to roll trying to get that mark." so i just added an increment everytime they didnt win or loose. I'm also away from eclipse and forget the format for one decimal place, so i didnt format the %. its %.1f or something i believe.
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