Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that does a simulation of the “Let’s Make a Deal” game. The prog

ID: 3666408 • Letter: W

Question

Write a program that does a simulation of the “Let’s Make a Deal” game. The program will take as input the number of simulations to be done. The game is simply choosing a door from 3 options, one of which has a prize behind it. Each simulation will require you to randomly generate a prize behind a door (door 0, door 1, or door 2). Next, the player randomly chooses a door (again door 0, 1, or 2). The simulation will then “reveal” a door that does not contain the prize. Then the player will follow two different strategies. Either stick to the door they currently have picked, or switch to the other door (there is only one that has not been revealed and is not the one they currently have). The player wins if at the end of the game the door they currently have matches the prize door. Keep track of how many times the player won employing both strategies (stay or switch). Calculate the average amount of games won for each strategy.

Due to the use of random numbers your outputs may vary but the trending towards 1 and 2 33

should happen.

Explanation / Answer

Check the code below for reference:

import java.util.Random;

  

class Deal{

  int prizeDoor;

  int playersDoor;

  int boobyShown;

  boolean trade;

  boolean win;

  Random rand = new Random();

  

  void showBooby(){

    boobyShown = prizeDoor;

    while( (boobyShown == prizeDoor) || (boobyShown == playersDoor) ){

      boobyShown = (int)(Math.random()*3);

    }

  }

  

  boolean outcome(){

    if(playersDoor == prizeDoor){

      return true;

    }

    else return false;

  }

  

  void simulateDeal(){

    prizeDoor = (int)(Math.random()*3);

    playersDoor = (int)(Math.random()*3);

    showBooby();

    trade = rand.nextBoolean();

    if(trade){

      playersDoor = 3 - boobyShown - playersDoor;

    }

    win = outcome();

  }

}

  

  

public class MontySimulator{

  public static void main(String[] args){

    int switchWin = 0;

    int switchLose = 0;

    int stayWin = 0;

    int stayLose = 0;

    Deal d = new Deal();

  

    for(int i = 0; i < 100000; i++){

      d.simulateDeal();

      if(d.trade){

        if(d.win){

          switchWin++;

        }

        else switchLose++;

      }

      else{

        if(d.win){

          stayWin++;

        }

        else stayLose++;

      }

    }

  

    System.out.println(" 100,000 deals simulated...");

    System.out.println(" Switched and won: " + switchWin);

    System.out.println(" Switched and lost: " + switchLose);

    System.out.println(" Stayed and won: " + stayWin);

    System.out.println(" Stayed and lost: " + stayLose);

  

    int resultSwitch = (switchWin*100) / (switchWin + switchLose);

    int resultStay = (stayWin*100) / (stayWin + stayLose);

    System.out.println(" Percent wins with switching doors: " + resultSwitch);

    System.out.println("Percent wins with keeping door: " + resultStay);

  }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote