import java.util.*; public class DoorGame { public static void main(String[] args) { int total=0,choice,choice2,door1,door2,door3; Random g = new Random(); Scanner in=new Scanner(System.in); System.out.println("In this game you will select one of 3 doors. There will be a cash prize behind the door."); System.out.println("You may take the money, or try to double it by opening a second door. If the second door contains more money, you double your initial choice."); System.out.println("If the second door contains less money, you lose it all!"); door1=g.nextInt(100)+1; // 1-100 door2=g.nextInt(60)+25; // 25-84 door3=g.nextInt(50)+30; // 30-79 do { System.out.print("Pick a door, 1-3: "); choice=in.nextInt(); } while(choice<1||choice>3); if(choice==1) { total+=door1; System.out.println("Congratulations, the door contained $" + door1); } else if(choice==2) { total+=door2; System.out.println("Congratulations, the door contained $" + door2); } else { total+=door3; System.out.println("Congratulations, the door contained $" + door3); } do { System.out.print("Select a second door (any door except " + choice + ", or 0 if you do not want to select another door: "); choice2=in.nextInt(); }while(choice2==choice||choice2<0||choice2>3); if(choice2!=0) { if(choice2==1) { if(door1>total) { System.out.println("Congratulations, door 1 contains $" + door1 + " so you double your money!"); total*=2; } else { System.out.println("I'm sorry, door 1 contains $" + door1 + " so you lose your money"); total=0; } } else if(choice2==2) { if(door2>total) { System.out.println("Congratulations, door 2 contains $" + door2 + " so you double your money!"); total*=2; } else { System.out.println("I'm sorry, door 2 contains $" + door2 + " so you lose your money"); total=0; } } if(choice2==3) { if(door3>total) { System.out.println("Congratulations, door 3 contains $" + door3 + " so you double your money!"); total*=2; } else { System.out.println("I'm sorry, door 3 contains $" + door3 + " so you lose your money"); total=0; } } } System.out.println("Thanks for playing, you leave us with $" + total); } }