jam/DoorTester

From ggc

Jump to: navigation, search

01 package jam;
02 
03 import wiki.Wiki;
04 import java.util.*;
05 /**
06  * All about my application here.
07  @author Jam Jenkins 
08  */
09 public class DoorTester
10 {
11   public static void main(String[] args)
12   {
13     Door door1=new Door(falsefalse1);
14     Door door2=new Door(falsefalse2);
15     Door door3=new Door(truefalse3);
16     Wiki.out.println("The doors to start:");
17     Wiki.out.println(door1);
18     Wiki.out.println(door2);
19     Wiki.out.println(door3);
20     Wiki.out.println("\nChoose a door (1, 2, or 3)");
21     Scanner scanner=new Scanner(Wiki.in);
22     int firstChoice=scanner.nextInt();
23     if(door1.canOpenFirst(firstChoice))
24     {
25       Wiki.out.println("Opening door 1 with a donkey behind it.")  ;
26       door1.open();
27     }
28     if(door2.canOpenFirst(firstChoice))
29     {
30       Wiki.out.println("Opening door 2 with a donkey behind it.")    ;
31       door2.open();
32     }
33     if(door3.canOpenFirst(firstChoice))
34     {
35       Wiki.out.println("Opening door 3 with a donkey behind it.")  ;
36       door3.open();
37     }
38 
39     Wiki.out.println("Stay or switch?");
40     String answer=scanner.next();
41     boolean won=false;
42     if(answer.toLowerCase().equals("stay"))
43     {
44       if(firstChoice==1)
45       {
46         if(door1.isPrize())
47           won=true;
48       }
49       if(firstChoice==2)
50       {
51         if(door2.isPrize())
52           won=true;
53       }
54       if(firstChoice==3)
55       {
56         if(door3.isPrize())
57           won=true;
58       }
59     }
60     else
61     {
62       if(firstChoice==1)
63       {
64         if(!door1.isPrize())
65           won=true;
66       }
67       if(firstChoice==2)
68       {
69         if(!door2.isPrize())
70           won=true;
71       }
72       if(firstChoice==3)
73       {
74         if(!door3.isPrize())
75           won=true;
76       }
77     }
78     door1.open();
79     door2.open();
80     door3.open();
81     if(won)
82       Wiki.out.println("You won a brand new Pinto!");
83     else
84       Wiki.out.println("You won your very own herd of male goats.");
85 
86 
87   }
88 }


Download/View jam/DoorTester.java





Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter