Question: Write a program to play the game, Craps in a loop. You will keep a running total of the number of rounds won, and rounds

Write a program to play the game, "Craps" in a loop. You will keep a running total of the number of rounds won, and rounds lost. Your program should play ten million rounds of craps.

When the program finishes, it will print out the percentage of wins in the format: "Player won 51.45% of the time."

In order to display the number with just two digits after the decimal point, Google "Java decimalformat" and study the examples you find.

You will need to use Math.random to generate random numbers. It will generate numbers in the interval [0,1). For each "virtual die", multiply the random number by 6, "cast" it to an integer (this will throw away the fractional part, and result in a number in the interval [0,5]). Then add 1, to get a number in the interval [1,6].

(You could also use Math.ceil to do this) Do this again for the second "virtual die", and add the two random numbers together to get a total in the interval [2,12].

In each round, the player rolls the pair of dice on a "come-out roll".

If the come-out roll is a 7 or 11, then the player wins. This scenario ends the round. If the come-out roll is a 2, 3 or 12, also known as "craps", the player loses. This also ends the round.

If the come-out roll is a 4, 5, 6, 8, 9 or 10, then that specific number becomes the player's point. The shooter continues to roll the dice until he or she rolls the point number or a 7. If the point number is rolled, then the player wins. If a 7 is rolled, the player loses.

WRITTEN IN JAVA USING ECLIPSE

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!