Question: To play craps, a player rolls two dice repeatedly until he wins or loses. If he makes a 7 or an 11 on the first

To play craps, a player rolls two dice repeatedly until he wins or loses. If he makes a 7 or an 11 on the first roll, he wins immediately. An initial roll of 2, 3, or 12 results in a loss. If he tosses a 4, 5, 6, 8, 9, or 10 on his first roll, then that number becomes his point. After a player makes a point, he continues rolling the dice and wins or loses according to the following rules: if he makes his point before rolling a seven, he wins; but if he roll a seven first, he loses. No other values, including 2, 3, 11 or 12, affect the games outcome once the player has established his point.

Write a program that plays craps. Your program should allow a user to play more than one game. Typical output appears below:

Enter 0 to roll the dice: 0 You rolled a 7 You win Play again? Enter 1 for yes: 1 Enter 0 to roll the dice: 0 You rolled a 4. Your point is 4. Continue rolling. Enter 0 to roll the dice: 0 You rolled a 3 Enter 0 to roll the dice: 0 You rolled a 5 Enter 0 to roll the dice: 0 You rolled a 7 You lose Play again? Enter 1 for yes: 0

Bye

Hint: To roll a single die, generate a random number between 1 and 6 inclusive. You can do this with the SecureRandom class in the java.security package. Use this formula: die1 = (num.nextInt(6) + 1);

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!