Write a program that plays craps
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 rolls a seven first, he loses.
No other values, including 2, 3, 11 or 12, affect the game’s 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 (int)(6 * Math.random()) + 1
12 years ago
Purchase the answer to view it
- craps.java