-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeal.java
More file actions
133 lines (125 loc) · 3.17 KB
/
Deal.java
File metadata and controls
133 lines (125 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/**
* Deal.java
* A Program that runs
* the Let's Make A Deal show.
*
* @author Huy Tu
* @version 1/21/2014
*/
public class Deal
{
//variable that tracks the curtain storing the prize
private int prize;
//variable that tracks the curtain that the contestant pick
private int pick;
//arrays storing all the names of the contestants
private String[] contestants = {"Jane", "Betty", "Frank", "Fred"};
/**
* No parameter constructor.
*/
public Deal()
{
}
/**
* Picking the prize curtain of Let's Make A Deal.
* @return Command Line Argument.
*/
public int prizeDeal()
{
prize = (int) (Math.random() * 3 + 1);
return prize;
}
/**
* Generating a different number from
* the two input numbers.
*
* @param prize Command Line Argument.
* @param pick Command Line Argument.
* @return Command Line Argument.
*/
public int pickDif(int prize, int pick)
{
int rand;
do
{
rand = (int) (Math.random() * 3 + 1);
}
while (rand == prize || rand == pick);
return rand;
}
/**
* Facilitate the Let's Make a Deal.
*
*/
public void play()
{
for (int i = 0; i < contestants.length; i++)
{
prizeDeal();
System.out.println("The winning curtain is " + prize);
stragP(contestants[i]);
System.out.println(contestants[i] + " selects curtain " + pick);
int opened = pickDif(prize, pick);
System.out.println("Monty opens curtain " + opened);
String strag = stragS(contestants[i], pick, opened);
System.out.println("" + contestants[i] + strag);
if (prize == pick)
{
System.out.println(contestants[i] + " wins " + "\n");
}
else
{
System.out.println(contestants[i] + " loses " + "\n");
}
}
}
/**
* Strategy of each contestant in originally picking.
*
* @param name Command Line Argument.
* @return Command Line Argument.
*/
public int stragP(String name)
{
if (name.equals("Jane") || name.equals("Betty"))
{
pick = 1;
}
else
{
pick = (int) (Math.random() * 3 + 1);
}
return pick;
}
/**
* Strategy from each contestant
* for switching.
*
* @param name Command Line Argument.
* @param current Command Line Argument.
* @param opened Command Line Argument.
* @return Command Line Argument.
*/
public String stragS(String name, int current, int opened)
{
String s = "";
if (name.equals("Jane") || name.equals("Frank"))
{
s += " does not switch";
}
else
{
pick = pickDif(current, opened);
s += " switches to " + pick;
}
return s;
}
/**
* @param args Command Line Argument
*/
public static void main(String[] args)
{
Deal a = new Deal();
a.play();
}
}