This is my code I am supposed to be simulating the game of craps: I am getting the right win and losses turn out but I can't get the probability correct. any suggestions?
please help the instructions are: In the game of craps, a pass line bet proceeds as follows. Two six-sided dice are rolled; the first roll of the dice in a craps round is called the “come out roll.” A come-out roll of 7 or 11 automatically wins, and a come out roll of 2, 3, or 12 automatically loses. 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 a 7 is rolled first, then the player loses. Write a program that simulates a game of craps using these rules without human input. Instead of asking for a wager, the program should calculate whether 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, you or the house? Note: To generate a random number x, where 0 x ≤< 1, use x = Math.random(); . For example, multiplying by 6 and converting to an integer results in an integer that is between 0 and 5.
public class Dice
{
public static void main(String[]args)
{
//declaring variables
int comeOutRoll1, comeOutRoll2;
int roll1, roll2;
int numW, numL;
int sum, sum2 = 0;
int thePoint = 0;
double probability;
//initializing variables
comeOutRoll1 = (int)(Math.random()*5);
comeOutRoll2 = (int)(Math.random()*5);
sum = comeOutRoll1 + comeOutRoll2;
numW = 0;
numL = 0;
for(int timesPlayed = 0; timesPlayed <= 10000; timesPlayed++)
{
switch(sum)
{
//adds how many wins and losses
case 2:
numL = numL +1;
break;
case 3:
numL = numL + 1;
break;
case 12:
numL = numL + 1;
break;
case 7:
numW = numW +1;
break;
case 11:
numW = numW +1;
break;
case 4:
thePoint = sum;
break;
case 5:
thePoint = sum;
break;
case 6:
thePoint = sum;
break;
case 8:
thePoint = sum;
break;
case 9:
thePoint = sum;
break;
case 10:
thePoint = sum;
break;
//if not any of these cases roll again
default:
roll1 = (int)(Math.random()*5);
roll2 = (int)(Math.random()*5);
sum2 = roll1 + roll2;
break;
}
if(sum2 == thePoint)
{
numW = numW +1;
}
else if(sum2 == 7)
{
numL = numL +1;
}
}
probability = (numW/(numW+numL));
System.out.println("Number of Wins: " + numW);
System.out.println("Number of Losses: " + numL);
System.out.println("The probability of winning is: " + probability + " percent");
}
}