Guest User

Untitled

a guest
Nov 17th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.56 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package pickadoor;
  6.  
  7. import java.util.Random;
  8. import java.util.Scanner;
  9.  
  10. /**
  11.  *
  12.  * @author Admin
  13.  */
  14. public class PickADoorClass {
  15.     int a = 0, b =  0, c = 0;
  16.     int[] myArray = new int[3];
  17.     int myChoice = 1;
  18.     int numLosses = 0;
  19.     int numWins = 0;
  20.    
  21.     public void chooseDoor()
  22.     {
  23.         System.out.println("Always Swap");
  24.         while(numWins + numLosses < 1000000)
  25.         {
  26.         myArray[0] = 1;
  27.         myArray[1] = 1;
  28.         myArray[2] = 2;
  29.         Random myRandom = new Random();
  30.        
  31.         while(a != 2 || b != 2 || c != 2)
  32.         {
  33.            
  34.             a = myArray[myRandom.nextInt(3)];
  35.             if(a == 2)
  36.             {
  37.                 c = 1; b = 1;
  38.                 break;
  39.             }
  40.             b = myArray[myRandom.nextInt(3)];
  41.             if(b == 2)
  42.             {
  43.                 c = 1; a = 1;
  44.                 break;
  45.             }
  46.             c = myArray[myRandom.nextInt(3)];
  47.             if(c == 2)
  48.             {
  49.                 a = 1; b = 1;
  50.             }
  51.         }
  52.         Scanner myScan = new Scanner(System.in);
  53.        
  54.         /*System.out.println("There are three doors, please pick a door(1, 2, or 3");
  55.         myChoice = myScan.nextInt();*/
  56.         myChoice = myRandom.nextInt(2);
  57.         removeDoor();
  58.         /*System.out.println("I will now reveal that door #" + removeDoor() + " is not the winning door");
  59.         System.out.println("Would you like to swap with door #" + otherDoor() + " (0 for no, 1 for yes)");
  60.         int answer = myChoice = myScan.nextInt();
  61.         if(answer == 1)
  62.             swapDoor();*/
  63.         swapDoor();
  64.         finalAnswer();
  65.         }
  66.         System.out.println("Wins:" + numWins + " Losses:" + numLosses);
  67.         numWins = 0;
  68.         numLosses = 0;
  69.         System.out.println("Always stay");
  70.         while(numWins + numLosses < 1000000)
  71.         {
  72.         myArray[0] = 1;
  73.         myArray[1] = 1;
  74.         myArray[2] = 2;
  75.         Random myRandom = new Random();
  76.        
  77.         while(a != 2 || b != 2 || c != 2)
  78.         {
  79.            
  80.             a = myArray[myRandom.nextInt(3)];
  81.             if(a == 2)
  82.             {
  83.                 c = 1; b = 1;
  84.                 break;
  85.             }
  86.             b = myArray[myRandom.nextInt(3)];
  87.             if(b == 2)
  88.             {
  89.                 c = 1; a = 1;
  90.                 break;
  91.             }
  92.             c = myArray[myRandom.nextInt(3)];
  93.             if(c == 2)
  94.             {
  95.                 a = 1; b = 1;
  96.             }
  97.         }
  98.         Scanner myScan = new Scanner(System.in);
  99.        
  100.         /*System.out.println("There are three doors, please pick a door(1, 2, or 3");
  101.         myChoice = myScan.nextInt();*/
  102.         myChoice = myRandom.nextInt(2);
  103.         removeDoor();
  104.         /*System.out.println("I will now reveal that door #" + removeDoor() + " is not the winning door");
  105.         System.out.println("Would you like to swap with door #" + otherDoor() + " (0 for no, 1 for yes)");
  106.         int answer = myChoice = myScan.nextInt();
  107.         if(answer == 1)
  108.             swapDoor();*/
  109.         finalAnswer();
  110.         }
  111.         System.out.println("Wins:" + numWins + " Losses:" + numLosses);
  112.     }
  113.    
  114.     public void removeDoor()
  115.     {
  116.         String myName = "";
  117.         if(myChoice == 1)
  118.         {
  119.             if(b == 2)
  120.             {
  121.                 c = 0;
  122.                 myName = "3";
  123.             }
  124.             else
  125.             {
  126.                 b = 0;
  127.                 myName = "2";
  128.             }
  129.         }
  130.         else if(myChoice == 2)
  131.         {
  132.             if(a == 2)
  133.             {
  134.                 c = 0;
  135.                 myName = "3";
  136.             }
  137.             else
  138.             {
  139.                 a = 0;
  140.                 myName = "1";
  141.             }
  142.         }
  143.         else
  144.         {
  145.             if(b == 2)
  146.             {
  147.                 a = 0;
  148.                 myName = "1";
  149.             }
  150.             else
  151.             {
  152.                 b= 0;
  153.                 myName = "2";
  154.             }
  155.         }
  156.         //return myName;
  157.     }
  158.    
  159.     public String otherDoor()
  160.     {
  161.         String myName = "";
  162.        
  163.         if(a == 0)
  164.         {
  165.             if(myChoice == 2)
  166.             {
  167.                 myName = "3";
  168.             }
  169.             else
  170.             {
  171.                 myName = "2";
  172.             }
  173.         }
  174.         else if(b == 0)
  175.         {
  176.             if(myChoice == 1)
  177.             {
  178.                 myName = "1";
  179.             }
  180.             else
  181.             {
  182.                 myName = "3";
  183.             }
  184.         }
  185.         else
  186.         {
  187.             if(myChoice == 1)
  188.             {
  189.                 myName = "2";
  190.             }
  191.             else
  192.             {
  193.                 myName = "1";
  194.             }
  195.         }
  196.         return myName;
  197.     }
  198.    
  199.     public void swapDoor()
  200.     {
  201.         if(myChoice == 1)
  202.         {
  203.             if(b == 0)
  204.             {
  205.                 myChoice = 3;
  206.             }
  207.             else
  208.             {
  209.                 myChoice = 2;
  210.             }
  211.         }
  212.         else if(myChoice == 2)
  213.         {
  214.             if(a == 0)
  215.             {
  216.                 myChoice = 3;
  217.             }
  218.             else
  219.             {
  220.                 myChoice = 1;
  221.             }
  222.         }
  223.         else
  224.         {
  225.             if(b == 0)
  226.             {
  227.                 myChoice = 1;
  228.             }
  229.             else
  230.             {
  231.                 myChoice = 2;
  232.             }
  233.         }
  234.     }
  235.    
  236.     public void finalAnswer()
  237.     {
  238.         if(myChoice == 1)
  239.         {
  240.             if(a == 2)
  241.             {
  242.                 //System.out.println("Congratulations, you won!");
  243.                 numWins++;
  244.             }
  245.             else
  246.             {
  247.                 //System.out.println("I'm sorry, you lost");
  248.                 numLosses++;
  249.             }
  250.         }
  251.         else if(myChoice == 2)
  252.         {
  253.             if(b == 2)
  254.             {
  255.                 //System.out.println("Congratulations, you won!");
  256.                 numWins++;
  257.             }
  258.             else
  259.             {
  260.                 //System.out.println("I'm sorry, you lost");
  261.                 numLosses++;
  262.             }
  263.         }
  264.         else
  265.         {
  266.             if(c == 2)
  267.             {
  268.                 //System.out.println("Congratulations, you won!");
  269.                 numWins++;
  270.             }
  271.             else
  272.             {
  273.                 //System.out.println("I'm sorry, you lost");
  274.                 numLosses++;
  275.             }
  276.         }
  277.     }
  278. }
Add Comment
Please, Sign In to add comment