Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Craps is a game played with two dice. Each die has six faces numbered 1 through

ID: 3595588 • Letter: C

Question

Craps is a game played with two dice. Each die has six faces numbered 1 through 6. You roll the dice and sum the numbers on the two upper faces of the dice.

The first roll of the dice in a craps round is called the “come out roll.”

If the come out roll is 2, 3, or 12, called craps, you lose.

If the come out roll is a 7 or 11, called a natural, you win.

If the come out roll is 4, 5, 6, 8, 9, or 10, that sum becomes the "point."The player then continues to roll the dice until either

a 7 is rolled (in which case they lose) or

the same "point" value is rolled (in which case they win).

The Program Details

Write a program, class name Craps, that simulates playing 10,000 rounds of craps. The 10,000 rounds must be programmed using a for loop. You must also declare the 10,000 as a constant.

During each round, on a single line, display the following:

The come out roll, and whether or not the players loses with craps, wins with a natural, or sets a point.

If the point is set, then show each roll of the dice, until either the seven or the point is rolled, and then display whether they won or lost.

After the last round is played, report the following:

how many wins there were,

how many losses there were, and

what the probability of winning at craps. You must use a printf statement here, display the probability as a percentage, and round the probability to two decimal places.

Note:

There is no user input.

The roll of the dice MUST be done with two random number generations, each being 1 to 6 and then adding them together. You cannot realistically simulate the rolling of two dice with a single random number generation from 1 to 12.

Below is a sample run. (For simplicity, I used only 13 rounds. Yours should use 10,000.)

-----------------------------This is my code, Idon't why my code cannot loop 10000 time or over 10000 time (wins+losses should be equal 10000)

public class NewEmpty {

public static void main(String[] args) {


//Declare a total number of rounds of the game
final int gameCount = 13;
int gameInitial;
//the sum of second round of the game
int sum2 = 0;
//The number of losses of the game
int losses = 0;
//The number of wins of the game
int wins = 0;
int point = 0;
double probabilityPercentage;//Declare rate of win is 0
for (gameInitial = 1; gameInitial <= gameCount; gameInitial++) {

//generate two random numbers of the dice
int dice1 = (int) (Math.random() * 6 + 1);
int dice2 = (int) (Math.random() * 6 + 1);
//the sum of the first round
int sum1 = dice1 + dice2;
switch (sum1) {
case 2:
case 3:
case 12:
System.out.println("craps: "+sum1+" you lose");
losses++;
break;
case 7:
case 11:
System.out.println("a natural "+sum1+" you win");
wins++;
break;
//if the result doesn't match with the first two case
default:
point = sum1;
  
System.out.print("your point is " + point+" ");
System.out.println("Continue rolling");   
  
//generate two random number of dice of the second round
do {
int dice3 = (int) (Math.random() * 6 + 1);
int dice4 = (int) (Math.random() * 6 + 1);
sum2 = dice3 + dice4;
//if sum of the dice is 7
  
if (sum2 == 7) {
System.out.println("you lose");
losses++;break;
} else if (sum2 == point) {
System.out.println("you win");
wins++;break;
}
}while(sum2!=7&&sum2!=point);
}   
  
}
//calaulate the probability of win the game
probabilityPercentage = ((double)wins / (wins + losses)) * 100;
System.out.println("FINAL RESULTS -------------");
System.out.println("Wins: " + wins + " Losses: " + losses);
System.out.printf("the probability of winning at craps is:%.2f%% ", probabilityPercentage);
}
}

Explanation / Answer


public class Craps {
public static void main(String[] args) {
  
//Declare a total number of rounds of the game
final int gameCount = 10000;
  
int gameInitial;
  
//the sum of second round of the game
int sum2 = 0;
  
//The number of losses of the game
int losses = 0;
//The number of wins of the game
int wins = 0;
int point = 0;
double probabilityPercentage;//Declare rate of win is 0
for (gameInitial = 1; gameInitial <= gameCount; gameInitial++) {
//generate two random numbers of the dice
int dice1 = (int) (Math.random() * 6 + 1);
int dice2 = (int) (Math.random() * 6 + 1);
//the sum of the first round
int sum1 = dice1 + dice2;
switch (sum1) {
case 2:
case 3:
case 12:
System.out.println("You rolled craps: "+sum1+". You lose.");
losses++;
break;
case 7:
case 11:
System.out.println("You rolled a natural: "+sum1+". You win.");
wins++;
break;
//if the result doesn't match with the first two case
default:
point = sum1;
  
System.out.print("Your point is: " + point+" ");
System.out.print("Continue rolling... ");
  
//generate two random number of dice of the second round
do {
int dice3 = (int) (Math.random() * 6 + 1);
int dice4 = (int) (Math.random() * 6 + 1);
sum2 = dice3 + dice4;
//if sum of the dice is 7
System.out.print(sum2+ " ");
if (sum2 == 7) {
System.out.println("You rolled 7. You lose.");
losses++;
break;
} else if (sum2 == point) {
System.out.println("You hit the point. You win!");
wins++;
break;
}
}while(sum2!=7&&sum2!=point);
}
  
}
//calculate the probability of win the game
probabilityPercentage = ((double)wins / (wins + losses)) * 100;
System.out.println("FINAL RESULTS -------------");
System.out.println("Wins: " + wins + " Losses: " + losses);
System.out.printf("The probability of winning at craps is: %.2f ", probabilityPercentage);
}
}

Samle output (Ony pasting last few lines because of charcter limitation)

FINAL RESULTS
-------------
Wins: 4918
Losses: 5082
The probability of winning at craps is: 49.18