Advertisement
Guest User

Untitled

a guest
May 24th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class DealRunner
  5. {
  6. public static void main(String[] args)
  7. {
  8. //instantiate Scanner object
  9. Scanner scan = new Scanner(System.in);
  10.  
  11. //prompt the user for the number of simulations to run
  12. System.out.println("How many simulations do you want to run?");
  13.  
  14. //assign input to variable
  15. int number;
  16. number = scan.nextInt();
  17.  
  18. //declare variables to store stopping condition for loop, prize loc, user guess,
  19. //door revealed, the new guess, and wins by changing
  20. int prizeLoc;
  21. int userGuess;
  22. int doorRevealed;
  23. int newGuess;
  24. int winsByChanging;
  25. int stop;
  26. int counter;
  27.  
  28. //loop through the number of simulations
  29. for (int i = 0; i <= number; i++) {
  30.  
  31. //instantiate a Deal object inside the loop
  32. Deal myObject = new Deal();
  33.  
  34. //get the user's guess and assign to a variable
  35. userGuess = myObject.getGuess();
  36.  
  37. //get the prize location and assign to a variable
  38. prizeLoc = myObject.getLoc();
  39.  
  40. //get the door which is revealed and assign to a variable
  41. doorRevealed = myObject.getRandom();
  42.  
  43. //get the new guess and assign to a variable
  44. newGuess = myObject.updateGuess();
  45.  
  46. //increment counter for loop
  47. counter++;
  48.  
  49. //determine if the new guess matches the prize location
  50. if (newGuess == prizeLoc) {
  51.  
  52. //increment the win count by changing
  53. winsByChanging++;
  54. }
  55.  
  56. //output the variables for each simulation
  57. System.out.println(myObject.toString());
  58.  
  59. }
  60. //output the probability of winning/not winning by switching
  61. System.out.println("Probablity of winning by switching:" + winsByChanging/100);
  62. System.out.println("Probability of not winning by switching:" + (counter-winsByChanging)/100);
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement