Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class DealRunner
- {
- public static void main(String[] args)
- {
- //instantiate Scanner object
- Scanner scan = new Scanner(System.in);
- //prompt the user for the number of simulations to run
- System.out.println("How many simulations do you want to run?");
- //assign input to variable
- int number;
- number = scan.nextInt();
- //declare variables to store stopping condition for loop, prize loc, user guess,
- //door revealed, the new guess, and wins by changing
- int prizeLoc;
- int userGuess;
- int doorRevealed;
- int newGuess;
- int winsByChanging;
- int stop;
- int counter;
- //loop through the number of simulations
- for (int i = 0; i <= number; i++) {
- //instantiate a Deal object inside the loop
- Deal myObject = new Deal();
- //get the user's guess and assign to a variable
- userGuess = myObject.getGuess();
- //get the prize location and assign to a variable
- prizeLoc = myObject.getLoc();
- //get the door which is revealed and assign to a variable
- doorRevealed = myObject.getRandom();
- //get the new guess and assign to a variable
- newGuess = myObject.updateGuess();
- //increment counter for loop
- counter++;
- //determine if the new guess matches the prize location
- if (newGuess == prizeLoc) {
- //increment the win count by changing
- winsByChanging++;
- }
- //output the variables for each simulation
- System.out.println(myObject.toString());
- }
- //output the probability of winning/not winning by switching
- System.out.println("Probablity of winning by switching:" + winsByChanging/100);
- System.out.println("Probability of not winning by switching:" + (counter-winsByChanging)/100);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement