Created
November 29, 2019 21:28
-
-
Save gitaficionado/abbaccd003a4f7860a4f575193b314a5 to your computer and use it in GitHub Desktop.
(Game: chance of winning at craps) Revise Exercise 6.30 to run it 10,000 times and display the number of winning games
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
public class ChanceAtWinningGraps_06_32 { | |
public static void main(String[] args) { | |
int winCount = __; | |
for (int i = ___; i < 10000; i++) { | |
int dice = _________(); | |
if (dice == ____ || dice == ___) { | |
_________________++; | |
} | |
else if (dice == 2 || dice == 3 || dice == 12) { | |
//System.out.println("You lose"); | |
} | |
else { | |
int point = _____; | |
//System.out.println("point is " + point); | |
do { | |
dice = ________(); | |
} while (dice != 7 && dice != point); | |
if (dice == 7) { | |
//System.out.println("You lose"); | |
} | |
else { | |
winCount++; | |
} | |
} | |
} | |
System.out.println(winCount); | |
} | |
// Get a dice | |
public static int getDice() { | |
int i1 = 1 + (int)(Math.random() * 6); | |
int i2 = 1 + (int)(Math.random() * 6); | |
// System.out.println("You rolled " + i1 + " + " + i2 + " = " + (i1 + i2)); | |
return i1 + i2; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment