Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

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

Database Systems For Advanced Applications 18th International Conference Dasfaa 2013 Wuhan China April 22 25 2013 Proceedings Part 2 Lncs 7826

Authors: Weiyi Meng ,Ling Feng ,Stephane Bressan ,Werner Winiwarter ,Wei Song

2013th Edition

3642374492, 978-3642374494

More Books

Students also viewed these Databases questions