Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package pickadoor;
- import java.util.Random;
- import java.util.Scanner;
- /**
- *
- * @author Admin
- */
- public class PickADoorClass {
- int a = 0, b = 0, c = 0;
- int[] myArray = new int[3];
- int myChoice = 1;
- int numLosses = 0;
- int numWins = 0;
- public void chooseDoor()
- {
- System.out.println("Always Swap");
- while(numWins + numLosses < 1000000)
- {
- myArray[0] = 1;
- myArray[1] = 1;
- myArray[2] = 2;
- Random myRandom = new Random();
- while(a != 2 || b != 2 || c != 2)
- {
- a = myArray[myRandom.nextInt(3)];
- if(a == 2)
- {
- c = 1; b = 1;
- break;
- }
- b = myArray[myRandom.nextInt(3)];
- if(b == 2)
- {
- c = 1; a = 1;
- break;
- }
- c = myArray[myRandom.nextInt(3)];
- if(c == 2)
- {
- a = 1; b = 1;
- }
- }
- Scanner myScan = new Scanner(System.in);
- /*System.out.println("There are three doors, please pick a door(1, 2, or 3");
- myChoice = myScan.nextInt();*/
- myChoice = myRandom.nextInt(2);
- removeDoor();
- /*System.out.println("I will now reveal that door #" + removeDoor() + " is not the winning door");
- System.out.println("Would you like to swap with door #" + otherDoor() + " (0 for no, 1 for yes)");
- int answer = myChoice = myScan.nextInt();
- if(answer == 1)
- swapDoor();*/
- swapDoor();
- finalAnswer();
- }
- System.out.println("Wins:" + numWins + " Losses:" + numLosses);
- numWins = 0;
- numLosses = 0;
- System.out.println("Always stay");
- while(numWins + numLosses < 1000000)
- {
- myArray[0] = 1;
- myArray[1] = 1;
- myArray[2] = 2;
- Random myRandom = new Random();
- while(a != 2 || b != 2 || c != 2)
- {
- a = myArray[myRandom.nextInt(3)];
- if(a == 2)
- {
- c = 1; b = 1;
- break;
- }
- b = myArray[myRandom.nextInt(3)];
- if(b == 2)
- {
- c = 1; a = 1;
- break;
- }
- c = myArray[myRandom.nextInt(3)];
- if(c == 2)
- {
- a = 1; b = 1;
- }
- }
- Scanner myScan = new Scanner(System.in);
- /*System.out.println("There are three doors, please pick a door(1, 2, or 3");
- myChoice = myScan.nextInt();*/
- myChoice = myRandom.nextInt(2);
- removeDoor();
- /*System.out.println("I will now reveal that door #" + removeDoor() + " is not the winning door");
- System.out.println("Would you like to swap with door #" + otherDoor() + " (0 for no, 1 for yes)");
- int answer = myChoice = myScan.nextInt();
- if(answer == 1)
- swapDoor();*/
- finalAnswer();
- }
- System.out.println("Wins:" + numWins + " Losses:" + numLosses);
- }
- public void removeDoor()
- {
- String myName = "";
- if(myChoice == 1)
- {
- if(b == 2)
- {
- c = 0;
- myName = "3";
- }
- else
- {
- b = 0;
- myName = "2";
- }
- }
- else if(myChoice == 2)
- {
- if(a == 2)
- {
- c = 0;
- myName = "3";
- }
- else
- {
- a = 0;
- myName = "1";
- }
- }
- else
- {
- if(b == 2)
- {
- a = 0;
- myName = "1";
- }
- else
- {
- b= 0;
- myName = "2";
- }
- }
- //return myName;
- }
- public String otherDoor()
- {
- String myName = "";
- if(a == 0)
- {
- if(myChoice == 2)
- {
- myName = "3";
- }
- else
- {
- myName = "2";
- }
- }
- else if(b == 0)
- {
- if(myChoice == 1)
- {
- myName = "1";
- }
- else
- {
- myName = "3";
- }
- }
- else
- {
- if(myChoice == 1)
- {
- myName = "2";
- }
- else
- {
- myName = "1";
- }
- }
- return myName;
- }
- public void swapDoor()
- {
- if(myChoice == 1)
- {
- if(b == 0)
- {
- myChoice = 3;
- }
- else
- {
- myChoice = 2;
- }
- }
- else if(myChoice == 2)
- {
- if(a == 0)
- {
- myChoice = 3;
- }
- else
- {
- myChoice = 1;
- }
- }
- else
- {
- if(b == 0)
- {
- myChoice = 1;
- }
- else
- {
- myChoice = 2;
- }
- }
- }
- public void finalAnswer()
- {
- if(myChoice == 1)
- {
- if(a == 2)
- {
- //System.out.println("Congratulations, you won!");
- numWins++;
- }
- else
- {
- //System.out.println("I'm sorry, you lost");
- numLosses++;
- }
- }
- else if(myChoice == 2)
- {
- if(b == 2)
- {
- //System.out.println("Congratulations, you won!");
- numWins++;
- }
- else
- {
- //System.out.println("I'm sorry, you lost");
- numLosses++;
- }
- }
- else
- {
- if(c == 2)
- {
- //System.out.println("Congratulations, you won!");
- numWins++;
- }
- else
- {
- //System.out.println("I'm sorry, you lost");
- numLosses++;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment