Use Monty Halljava file below under assignment rubric and co

Use Monty Hall.java file below under assignment rubric and complete please.. need help !

Solution

/**
* Created by Joon S. Lee on 8/23/15.
*
* The Monty Hall Problem
* Here\'s a fun and perhaps surprising statistical riddle.
* In a gameshow, contestants try to guess which of 3 closed doors contain a cash prize
* (goats are behind the other two doors). Of course, the odds of choosing the correct door are 1 in 3.
* As a twist, the host of the show occasionally opens a door after a contestant makes his or her choice.
* This door is always one of the two the contestant did not pick, and is also always one of the goat doors
* (note that it is always possible to do this, since there are two goat doors). At this point, the contestant
* has the option of keeping his or her original choice, or swtiching to the other unopened door.
* The question is: is there any benefit to switching doors?
* The answer surprises many people who haven\'t heard the question before.
* We can answer the problem by running simulations in Java.
* We\'ll do it in several parts.
*/

import java.util.Random;
import java.util.ArrayList;

public class MontyHall {

// First, write a function called simulate_prizedoor.
// This function will simulate the location of the prize in many games -- see the detailed specification below:
//
//    Function
//    --------
//    simulate_prizedoor
//
//    Generate a random array of 0s, 1s, and 2s, representing
//    hiding a prize between door 0, door 1, and door 2
//
//    Parameters
//    ----------
//    nsim : int
//    The number of simulations to run
//
//    Returns
//    -------
//    sims : ArrayList
//    Random ArrayList of 0s, 1s, and 2s
//
    static ArrayList<Integer> simulate_prizedoor(int nsim) {
        // COMPLETE THIS PART
   //declartaion of valriables for generating the random numbers
   int min=0,max=2,n,i,rnum;

   //definition of the array list al which holds the prize at the back of the number of the door
   ArrayList al=new ArrayList();

   //definining the random number variable
   Random rn = new Random();

   //loop for generating the 3 random number and assiging in the array list using al.add meth
   for(int j=1;j<=3;j++)
   {
       rnum = Math.abs(rn.nextInt(3));
       al.add(rnum);
   }
//   retruning the array list to the calling function
   return al;
    }

// Next, write a function that simulates the contestant\'s guesses for nsim simulations.
// Call this function simulate_guess. The specs:
//
//    Function
//    --------
//    simulate_guess
//
//    Return any strategy for guessing which door a prize is behind. This
//    could be a random strategy, one that always guesses 2, whatever.
//
//    Parameters
//    ----------
//    nsim : int
//    The number of simulations to generate guesses for
//
//    Returns
//    -------
//    guesses : ArrayList
//    An ArrayList of guesses. Each guess is a 0, 1, or 2
//
    static ArrayList<Integer> simulate_guess(int nsim) {
        // COMPLETE THIS PART
   int min=0,max=2,n,i,rnum;

   //definition of the array list gl which holds the guess list
   ArrayList gl=new ArrayList();

   //definining the random number variable
   Random rn = new Random();

   //loop for generating the 3 random number and assiging in the array list using al.add meth
   for(int j=1;j<=3;j++)
   {
       rnum = Math.abs(rn.nextInt(3));
       gl.add(rnum);
   }
//   retruning the array list to the calling function
   return gl;


    }

// Next, write a function, goat_door, to simulate randomly revealing one of the goat doors
// that a contestant didn\'t pick.
//
//    Function
//    --------
//    goat_door
//
//    Simulate the opening of a \"goat door\" that doesn\'t contain the prize,
//    and is different from the contestants guess
//
//    Parameters
//    ----------
//    prizedoors : ArrayList
//    The door that the prize is behind in each simulation
//    guesses : ArrayList
//    THe door that the contestant guessed in each simulation
//
//    Returns
//    -------
//    goats : ArrayList
//    The goat door that is opened for each simulation. Each item is 0, 1, or 2, and is different
//    from both prizedoors and guesses
//
    static ArrayList<Integer> goat_door(ArrayList<Integer> prizedoors, ArrayList<Integer> guesses) {

        // COMPLETE THIS PART
   Random rnum=new Random(); //declare variable for rndom number geneartion
   ArrayList c1=new ArrayList(); // declare arraylist to hold the result of comparison
   int result;
   for(int i =0;i<=2;i++) // loop to retrieve the prizedoor and guesses
   {
   do
   {
                result = rnum.nextInt(3);
   } while (result ==prizedoors.get(i) || result == guesses.get(i));
// repeat the step to check whether the result (on the basus of random number matches with either the element of prizedoor or guesses
   c1.add(result); //adding the result to c1 array list
   }
   return c1;

    }

// Write a function, switch_guess, that represents the strategy of always switching a guess after the goat door is opened.
//
//    Function
//    --------
//    switch_guess
//
//    The strategy that always switches a guess after the goat door is opened
//
//    Parameters
//    ----------
//    guesses : ArrayList
//    Array of original guesses, for each simulation
//    goatdoors : ArrayList
//    Array of revealed goat doors for each simulation
//
//    Returns
//    -------
//    The new door after switching. Should be different from both guesses and goatdoors
//
    static ArrayList<Integer> switch_guess(ArrayList<Integer> guesses, ArrayList<Integer> goatdoors) {

        // COMPLETE THIS PART

   Random rnum=new Random(); //declare variable for rndom number geneartion
   ArrayList sl=new ArrayList(); // declare arraylist to hold the result of comparison after switch
   int result;
   for(int i =0;i<=2;i++) // loop to retrieve the guesses and goatdoors
   {
   do
   {
                result = rnum.nextInt(3);
   } while (result ==goatdoors.get(i) || result == guesses.get(i));
// repeat the step to check whether the result (on the basus of random number matches with either the element of goatdoors or guesses
   sl.add(result); //adding the result to c1 array list
   }
   return sl;

    }

// Last function: write a win_percentage function that takes an array of guesses and prizedoors,
// and returns the percent of correct guesses
//
//    Function
//    --------
//    win_percentage
//
//    Calculate the percent of times that a simulation of guesses is correct
//
//    Parameters
//    -----------
//    guesses : ArrayList
//    Guesses for each simulation
//    prizedoors : ArrayList
//    Location of prize for each simulation
//
//    Returns
//    --------
//    percentage : number between 0 and 100
//    The win percentage
//
    static double win_percentage(ArrayList<Integer> guesses, ArrayList<Integer> prizedoors) {

        // COMPLETE THIS PART
   double per,num;
   int i;
   int win=0;
   for(i=0;i<=2;i++)
   {  
       if(guesses.get(i)==prizedoors.get(i))
       {
           win++;  
       }
   }
  
   per=win/3*100;
   return(per);

    }

    public static void main(String[] Args) {
        int number_of_trials = 10;

        // DO NOT MAKE CHANGES TO THE MAIN FILE
        ArrayList<Integer> prize = simulate_prizedoor(number_of_trials);
        System.out.println(prize);

        ArrayList<Integer> guess = simulate_guess(number_of_trials);
        System.out.println(guess);
      
        ArrayList<Integer> goat = goat_door(prize, guess);
        System.out.println(goat);
      
        ArrayList<Integer> new_door = switch_guess(guess, goat);
        System.out.println(new_door);

        System.out.println(\"\ Win Percentage when not changing the door: \" + win_percentage(guess, prize));
        System.out.println(\"\ Win Percentage after changing the door: \" + win_percentage(new_door, prize));
        // DO NOT MAKE CHANGES TO THE MAIN FILE
    }

}

Use Monty Hall.java file below under assignment rubric and complete please.. need help !Solution/** * Created by Joon S. Lee on 8/23/15. * * The Monty Hall Prob
Use Monty Hall.java file below under assignment rubric and complete please.. need help !Solution/** * Created by Joon S. Lee on 8/23/15. * * The Monty Hall Prob
Use Monty Hall.java file below under assignment rubric and complete please.. need help !Solution/** * Created by Joon S. Lee on 8/23/15. * * The Monty Hall Prob
Use Monty Hall.java file below under assignment rubric and complete please.. need help !Solution/** * Created by Joon S. Lee on 8/23/15. * * The Monty Hall Prob
Use Monty Hall.java file below under assignment rubric and complete please.. need help !Solution/** * Created by Joon S. Lee on 8/23/15. * * The Monty Hall Prob

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site