Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Need help with probability assignment

1. ## Need help with probability assignment

In the game of Craps, a "Pass Line" bet proceeds as follows. Using two six-sided dice, the first roll of the dice in a craps round is called the "Come Out Roll." The bet immediately wins when the come out roll is 7 or 11, and loses when the come out roll is 2, 3, or 12. If 4, 5, 6, 8, 9, or 10 is rolled on the come out roll, that number becomes "the point." The player keeps rolling the dice until either 7 or the point is rolled. If the point is rolled first, then the player wins the bet. If the player rolls a 7 first, then the player loses.
Write a program that plays the game of Craps using the rules stated above so that it simulates a game without human input. Instead of asking for a wager, the program should just calculate if the player would win or lose. The program should simulate rolling the two dice and calculate the sum. Add a loop so that the program plays 10,000 games. Add counters that count how many times the player wins, and how many times the player loses. At the end of the 10,000 games, compute the probability of winning, i.e. Wins / (Wins + Losses) and output this value. Over the long run, who is going to win the most games of Craps, you or the house?

Note: To generate a random number x, where 0 <= x < 1, use x = Math.random(); . For example, multiplying by six and converting to an integer results in an integer that is from 0 to 5.

Use a nested loop, with the outer loop for the number of games and an inner loop for the scenario of rolling the point.

can anyone help me with this please?

this is all i have so far.

public static void main(String[] args) {

Random diceRoller = new Random();
double NUM_GAMES;
for (NUM_GAMES = 10000)
{
for (int i = 1; i <= 12; i++) {
int roll = diceRoller.nextInt(11) + 2;
System.out.println(roll);
}

}
}

i am so stumped. i understand what the assignment is all about. i'm supposed to create a program that would simulate a dice roll for 10,000 times but how am I supposed to do taht by using loops? The assignment says to use a nested loop but I'm not sure how. Am I supposed to define the constants using the "private static final int" for the counts, wins and losses? If someone can help me with this that would be greatly appreciated.

2. ## Re: Need help with probability assignment

Your outer loop needs to repeat 10000 times. Right now you have...

for (NUM_GAMES = 10000)

...but this won't work. All you're doing is telling the for loop to set the value of NUM_GAMES to 10000; you're not actually testing anything. The syntax for a for-loop is

for(VariableDeclaration; TestExpression; Increment)

Right now, you have the declaration (NUM_GAMES = 10000), but think about this: do you start at the 10000th game, or the 1st game? Then, for the test: you want the loop to continue as long as NUM_GAMES is less than or equal to 10000. Finally, the increment (easy): every time a game is completed, you add one to the current value of NUM_GAMES.