Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional IPhone And IPad Database Application Programming

Authors: Patrick Alessi

1st Edition

0470636173, 978-0470636176

More Books

Students also viewed these Databases questions