Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Could anyone help me with this question? ****JAVA SCRIPT**** Finish the simulation program of the Monty Hall paradox that was discussed in class. Your program

Could anyone help me with this question?

****JAVA SCRIPT****

  1. 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 what I have for the code so far! ****JAVA SCRIPT****

1 import java.util.*; 2 3 public class Door { 4 boolean open; 5 boolean hasGrandPrize; 6 boolean chosenByContestant; 7 } 8 public class Game { 9 Door door1, door2, door3; 10 void setUpGame() { 11 door1 = new Door();door2 = new Door();door3 = new Door(); 12 // initialize all the Door variables to false 13 Random r = new Random(); 14 int grandPrizeDoor = r.nextInt(3); 15 switch(grandPrizeDoor) { 16 case 0: 17 door1.hasGrandPrize = true; break; 18 case 1: 19 door2.chosenByContestant = true;break; 20 case 3: 21 door3.chosenByContestant = true;break; 22 } 23 } 24 25 void printStateOfDoors() { 26 System.out.println("Door 1 is " + 27 (door1.open ? " open, " : "not open, ") + 28 (door1.hasGrandPrize ? "is the grand prize, and " : "is not the grand prize, and ") + 29 (door1.chosenByContestant ? "is chosen." : "is not chosen.") ); 30 System.out.println("Door 2 is " + 31 (door2.open ? " open, " : "not open, ") + 32 (door2.hasGrandPrize ? "is the grand prize, and " : "is not the grand prize, and ") + 33 (door2.chosenByContestant ? "is chosen." : "is not chosen.") ); 34 System.out.println("Door 3 is " + 35 (door3.open ? " open, " : "not open, ") + 36 (door3.hasGrandPrize ? "is the grand prize, and " : "is not the grand prize, and ") + 37 (door3.chosenByContestant ? "is chosen." : "is not chosen.") ); 38 } 39 40 public class Game { 41 Door door1, door2, door3; 42 void setUpGame() { // shown earlier} 43 door1 = new Door();door2 = new Door();door3 = new Door(); 44 void contestantChooseDoor() { 45 Random r = new Random(); 46 int contestantDoor = r.nextInt(3); 47 switch(contestantDoor) { 48 case 0: door1.chosenByContestant = true; break; 49 case 1: door2.chosenByContestant = true; break; 50 case 2: door3.chosenByContestant = true; break; 51 } 52 } 53 } 54 55 public class PlayManyGames { 56 public static void main(String[] args) { 57 Game theGame = new Game(); 58 theGame.setUpGame(); 59 theGame.printStateOfDoors(); 60 theGame.contestantChooseDoor(); 61 theGame.printStateOfDoors(); 62 } 63 } 64 65 public class Game { 66 Door door1, door2, door3; 67 static Random r = new Random(); 68 void setUpGame() { 69 int grandPrizeDoor = r.nextInt(3); 70 switch(grandPrizeDoor) { 71 // etc. 72 } 73 void contestantChooseDoor() { 74 int contestantDoor = r.nextInt(3); 75 switch(contestantDoor) { 76 // etc. 77 } 78 } 79

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

Information Modeling And Relational Databases

Authors: Terry Halpin, Tony Morgan

2nd Edition

0123735688, 978-0123735683

More Books

Students also viewed these Databases questions