Question: Hi! I need help with code for standard 7/11 program in Java. Please, give me an answer based on code below. Here are code and

Hi! I need help with code for standard 7/11 program in Java. Please, give me an answer based on code below. Here are code and requrements:

Requrements:

Write an application that runs 1,000,000 games of craps and answers the following questions:

1) How many games are won on the first roll, second roll, , twentieth roll, and after the twentieth roll?

2) How many games are lost on the first roll, second roll, , twentieth roll, and after the twentieth roll?

3) What are the chances of winning at craps?

4) What is the average length of a game of craps?

Code which I have:

import java.util.Random;

public class Craps {

private static final Random randomNumbers = new Random(); private enum Status { CONTINUE, WON, LOST }; private static final int SNAKE_EYES = 2; private static final int TREY = 3; private static final int SEVEN = 7; private static final int YO_LEVEN = 11; private static final int BOX_CARS = 12;

public static void main( String[] args ) { int myPoint = 0; Status gameStatus; int sumOfDice = rollDice();

switch ( sumOfDice ) { case SEVEN: case YO_LEVEN: gameStatus = Status.WON; break; case SNAKE_EYES: case TREY: case BOX_CARS: gameStatus = Status.LOST; break; default: gameStatus = Status.CONTINUE; myPoint = sumOfDice; System.out.printf( "Point is %d ", myPoint ); break;

}

while ( gameStatus == Status.CONTINUE ) { sumOfDice = rollDice();

if ( sumOfDice == myPoint ) gameStatus = Status.WON; else if ( sumOfDice == SEVEN ) gameStatus = Status.LOST; }

if ( gameStatus == Status.WON ) System.out.println( "Player wins" ); else System.out.println( "Player loses" ); }

public static int rollDice() {

int die1 = 1 + randomNumbers.nextInt( 6 ); int die2 = 1 + randomNumbers.nextInt( 6 ); int sum = die1 + die2; System.out.printf( "Player rolled %d + %d = %d ", die1, die2, sum ); return sum; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!