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

I need this program in Java. A contestant is given a choice of three doors. Behi

ID: 3793353 • Letter: I

Question

I need this program in Java.

A contestant is given a choice of three doors. Behind one door there is an expensive car, behind the other 2 doorsthere is a goat.

After the contestant makes an initial guess, the announcer peeks behind the other two doors and eliminates one of them that does not have the car behind it. For example, if the initial guess is door 2 and the car is behind door 3, then the announcer will show that there is a goat behind door 1.

If the initial guess is correct, the announcer will randomly decide which of the other two doors to eliminate. For example, if the initial guess is door 2 and the car is behind door 2, the announcer will randomly decide whether to show a goat behind door 1 or a goat behind door 3. After the initial guess has been made and the announcer has eliminated one of the other doors, the contestant must then decide if is they want to keep the first choice of pick the other remaining door.

This program will simulate the game show and that it is better to always switch choices. These are the steps that must be taken.

1. You will prompt the user to enter the number of times he or she wants to play this game.

2. You will create a variable to keep track of the number of times the contestant wins by switching.

3. Generate a random number between 1 and 3 (inclusive) that will denote the door that conceals the prize.

4. Generate another random number between 1 and 3 (inclusive) that will denote the guess the contestant makes.

5. From those two numbers, compute a number that does not conceal the prize nor is it the contestant's guess. This is the door that is opened by the host and we shall call it view.

6. At this point the contestant changes his mind makes newGuess that is not the original guess nor is it the view.

7. You will compare the value of the newGuess with that of prize. If they are te same, the contestant will won by switching, and you increment the variable that was keeping track of that.

8. You will run this simulation for however many times that user had specified.

9. To obtain the probability for winning if you switch divide the number of times the contestant wins by the total number of games played.

10. To obtain the probability of winning by not switching subtract the above number from one.

11. The probabiliites will be expressed to 2 places of decimals.

A sample session and output will look as follows:

Enter the number of times you want to play: 10

Prize Guess View New Guess 2 2 3 1 1 3 2 1 1 1 2 3 3 1 2 3 3 1 2 3 3 1 2 3 2 2 3 1 2 1 3 2 3 2 1 3 2 1 3 2

Probability of winning if you switch = 0.70 Probability of winning if you do not switch = 0.30

Explanation / Answer

/**
* @(#)Game_Car.java
*
*
* @author
* @version 1.00 2017/2/16
*/

import java.util.Scanner;
import java.math.*;
public class Game_Car {
   static int win; // define static variable win
   static int n; // define static variable total number of games
   public Game_Car() {
}
    public static void main(String args[])
    {
        Scanner sc1=new Scanner(System.in); // define object of scanner calss for taking input
        System.out.println("Enter the number of times you want to play: ");
        n=sc1.nextInt(); // Take Input System console
        int rand_num;
        int prize[]=new int[n]; // prize array
        int guess[]=new int[n];// Guess array
        int view[]=new int[n];// View array
        int new_guess[]=new int[n];
        System.out.println("Prize Guess View New View");
        for (int i=0;i<n;i++)
        {
            prize[i] = (int)(Math.random() * ((3 - 1) + 1)) + 1;
            guess[i] = (int)(Math.random() * ((3 - 1) + 1)) + 1;
            do
            {
                view[i] = ((int)(Math.random() * ((3 - 1) + 1)) + 1);
            }while(view[i]==prize[i] || view[i]==guess[i]); // Create view from the reamining values
            do
            {
                new_guess[i] = ((int)(Math.random() * ((3 - 1) + 1)) + 1); // Create new Guess from the reamining values
            }while(new_guess[i]==guess[i] || new_guess[i]==view[i]);
            System.out.println(""+prize[i]+" "+guess[i]+" "+view[i]+" "+new_guess[i]);
            if(new_guess[i]==prize[i])
                win++;
        }
        double win_prob_sw=(double)win/n; // Winning Probability
        double win_prob_nsw=(double)(n-win)/n; // Loosing Probability
        System.out.println("Probability of winning if you switch ="+win_prob_sw);
        System.out.println("Probability of winning if you do not switch = "+win_prob_nsw);
    }
}

// Output

--------------------Configuration: <Default>--------------------
Enter the number of times you want to play:
10
Prize        Guess       View       New View
1           2           3           1
1           3           2           1
1           1           2           3
2           1           3           2
1           1           2           3
3           3           2           1
3           2           1           3
2           3           1           2
2           1           3           2
3           1           2           3
Probability of winning if you switch =0.7
Probability of winning if you do not switch = 0.3

Process completed.

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