Created
November 29, 2019 21:05
-
-
Save gitaficionado/acbe0b9fa68e5a95d8cdba77c9196c0d to your computer and use it in GitHub Desktop.
Write a program to play a variation of the game. See the documentation in the program for more information.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**Game: craps) Craps is a popular dice game played in casinos. | |
*Write a program to play a variation of the game, as follows:Roll two dice. | |
*Each die has six faces representing values 1, 2, ..., and 6, respec-tively. | |
*Check the sum of the two dice. If the sum is 2, 3, or 12 (called craps), | |
*you lose; if the sum is 7 or 11 (called natural), you win; if the sum is | |
*another value (i.e., 4, 5, 6, 8, 9, or 10), a point is established. | |
*Continue to roll the dice until either a 7 or the same point value is rolled. | |
*If 7 is rolled, you lose. Otherwise, you win.Your program acts as a single player | |
*See page 222 in the Liang textbook for more information. | |
*/ | |
public class Craps_06_30 { | |
public static void main(String[] args) { | |
int dice = getDice(); | |
if (dice == __ || dice == ___) { | |
System.out.println("You win"); | |
System.exit(1); | |
} | |
else if (dice == 2 || dice == 3 || dice == 12) { | |
System.out.println("You lose"); | |
System.exit(2); | |
} | |
int point = dice; | |
System.out.println("point is " + point); | |
do { | |
dice = getDice(); | |
} while (dice != ___ && dice != point); | |
if (dice == __) | |
System.out.println("You lose"); | |
else | |
System.out.println("You win"); | |
} | |
// Get a dice | |
public static int __________________() { | |
int ___ = 1 + (int)(Math.random() * 6); | |
int ___ = 1 + (int)(Math.random() * 6); | |
System.out.println("You rolled " + i1 + " + " + i2 + " = " + (___ + ___)); | |
return ___ + ____; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment