Question: Could anyone help me add these two methods to the code below by tonight please!! In the Game class, you need to include two new
Could anyone help me add these two methods to the code below by tonight please!!
In the Game class, you need to include two new methods. One is called MonteOpenDoor(), the other one is swtichDoor().
Monte opens a door which is not chosen by contestant and does not have the grand prize MonteOpenDoor()
if the contestant wants to switch door, he/she switches to the door that was not previously chosen and not open by Monte SwitchDoor()
1 import java.util.*; 2 3 public class Game { 4 Door door1 = new Door(), door2 = new Door(), door3 = new Door(); 5 6 static Random r = new Random(); 7 8 9 void setUpGame() { 10 int grandPrizeDoor = r.nextInt(3); 11 switch (grandPrizeDoor) { 12 case 0: 13 door1.hasGrandPrize = true; break; 14 case 1: 15 door2.hasGrandPrize = true; break; 16 case 2: 17 door3.hasGrandPrize = true; break; 18 } 19 } 20 21 void contestantChooseDoor() { 22 int contestantDoor = r.nextInt(3); 23 switch (contestantDoor) { 24 case 0: 25 door1.chosenByContestant = true; 26 door2.chosenByContestant = false; 27 door3.chosenByContestant = false; 28 break; 29 case 1: 30 door1.chosenByContestant = false; 31 door2.chosenByContestant = true; 32 door3.chosenByContestant = false; 33 break; 34 case 2: 35 door1.chosenByContestant = false; 36 door2.chosenByContestant = false; 37 door3.chosenByContestant = true; 38 break; 39 } 40 } 41 42 43 boolean ifUserWon() { 44 if ((door1.hasGrandPrize && door1.chosenByContestant) || (door2.hasGrandPrize && door2.chosenByContestant) 45 || (door3.hasGrandPrize && door3.chosenByContestant)) { 46 return true; 47 } 48 return false; 49 } 50 51 52 void printStateOfDoors() { 53 System.out.println("Door 1 is " + (door1.open ? " open, " : "not open, ") 54 + (door1.hasGrandPrize ? "is the grand prize, and " : "is not the grand prize, and ") 55 + (door1.chosenByContestant ? "is chosen." : "is not chosen.")); 56 System.out.println("Door 2 is " + (door2.open ? " open, " : "not open, ") 57 + (door2.hasGrandPrize ? "is the grand prize, and " : "is not the grand prize, and ") 58 + (door2.chosenByContestant ? "is chosen." : "is not chosen.")); 59 System.out.println("Door 3 is " + (door3.open ? " open, " : "not open, ") 60 + (door3.hasGrandPrize ? "is the grand prize, and " : "is not the grand prize, and ") 61 + (door3.chosenByContestant ? "is chosen." : "is not chosen. ")); 62 } 63 64 }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
