Question: These are the instructions: **JAVA SCRIPT ** Add Game methods for Monte choosing a door to open The player switching or not Deciding if the

These are the instructions:

**JAVA SCRIPT **

Add Game methods for

Monte choosing a door to open

The player switching or not

Deciding if the player has won

Add PlayManyGames code to

Call the new Game methods

Put everything in a loop

Prompt the user for # of trials, switching policy

Display the results

Finish the simulation program of the Monty Hall paradox that was discussed in class. Your program should ask the user if she wants to always switch or never switch, and then silently simulate the game 10,000 times given this decision. Dont repeatedly ask the user for her decision on each trial! Dont print out any debugging text! Print out only the overall fraction of times the player wins the fabulous grand prize.

This is the code I have so far:

1 import java.util.*; 2 3 4 public class Door { 5 boolean open; 6 boolean hasGrandPrize; 7 boolean chosenByContestant; 8 } 9 public class Game { 10 Door door1, door2, door3; 11 static Random r = new Random(); 12 void setUpGame() { 13 int grandPrizeDoor = r.nextInt(3); 14 switch(grandPrizeDoor) { 15 case 0: 16 door1.hasGrandPrize = true; break; 17 case 1: 18 door2.hasGrandPrize = true; break; 19 case 2: 20 door2.hasGrandPrize = true; break; 21 } 22 void contestantChooseDoor() { 23 int contestantDoor = r.nextInt(3); 24 switch(contestantDoor) { 25 case 0: door1.chosenByContestant = true; break; 26 case 1: door2.chosenByContestant = true; break; 27 case 2: door3.chosenByContestant = true; break; 28 } 29 } 30 void printStateOfDoors() { 31 System.out.println("Door 1 is " + 32 (door1.open ? " open, " : "not open, ") + 33 (door1.hasGrandPrize ? "is the grand prize, and " : "is not the grand prize, and ") + 34 (door1.chosenByContestant ? "is chosen." : "is not chosen.") ); 35 System.out.println("Door 2 is " + 36 (door2.open ? " open, " : "not open, ") + 37 (door2.hasGrandPrize ? "is the grand prize, and " : "is not the grand prize, and ") + 38 (door2.chosenByContestant ? "is chosen." : "is not chosen.") ); 39 System.out.println("Door 3 is " + 40 (door3.open ? " open, " : "not open, ") + 41 (door3.hasGrandPrize ? "is the grand prize, and " : "is not the grand prize, and ") + 42 (door3.chosenByContestant ? "is chosen." : "is not chosen.") ); 43 } 44 public class PlayManyGames { 45 public static void main(String[] args) { 46 Game theGame = new Game(); 47 theGame.setUpGame(); 48 theGame.printStateOfDoors(); 49 theGame.contestantChooseDoor(); 50 theGame.printStateOfDoors(); 51 } 52 }

If anyone could help me with this that would be great!!

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!