import java.util.Random;
import java.util.Scanner;

public class MontyHall
{
 public static void main(String[] args)
 {
  Scanner keyboard = new Scanner(System.in);
  Random rnd = new Random();
  int wins = 0;
  for (int i = 0; i < 100; i++)
  {
      int prize = rnd.nextInt(3)+1; // Door with the prize
      int choice;
      
      // Player picks a door
      System.out.println("Pick a door from 1-3.");
      choice = rnd.nextInt(3)+1;  //keyboard.nextInt();
      System.out.println("We picked " + choice);
      
      
    // Reveal a door without the prize
    int doorToReveal = 0;
    int switchDoor = 0;
    if (choice == 1)
    {
      if (prize ==2)
      {
        doorToReveal = 3;
        switchDoor = 2;
      }
      else
      {
        doorToReveal = 2;
        switchDoor = 3;
      }
    }
    else if (choice == 2)
    {
      if (prize == 1)
      {
        doorToReveal = 3;
        switchDoor = 1;
      }
      else
      {
        doorToReveal = 1;
        switchDoor = 3;
      }
    }
    else  // choice is 3
    {
      if (prize ==2)
      {
        doorToReveal = 1;
        switchDoor = 2;
      }
      else
      {
        doorToReveal = 2;
        switchDoor = 1;
      }
    }
    System.out.println("Behind door number " + doorToReveal + " is rice-a-roni!");
    
    // Allow user to switch doors
    System.out.println("Pick a new door from 1-3.");
    //choice = keyboard.nextInt();
    System.out.println("If switching we go to " + switchDoor);
    choice = switchDoor;
    
    // Output if won
    if (choice == prize)
    {
      System.out.println("You win $1,000,000!");
      wins++;
    }
    else
      System.out.println("Sorry, you win rice-a-roni. The $$$ was behind " + prize);
  }
  System.out.println("We won " + wins + " times.");
 }
}