-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSlotMachine.java
More file actions
286 lines (251 loc) · 6.99 KB
/
SlotMachine.java
File metadata and controls
286 lines (251 loc) · 6.99 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
import java.text.DecimalFormat;
import java.util.*;
public class SlotMachine {
static Scanner scan = new Scanner(System.in);
private String name;
private double balance;
private int numJackpot;
private double jackpotPay;
private int numWin;
private double winPay;
private double hopper;
private int oddsJackpot;
private int oddsWin;
//constructors
public SlotMachine() {
makeSlotMachine();
}
public SlotMachine(String name, double balance, int numJackpot, double jackpotPay, int numWin, double winPay,
double hopper, int oddsJackpot, int oddsWin) {
setName(name);
setBalance(balance);
setNumJackpot(numJackpot);
setJackpotPay(jackpotPay);
setNumWin(numWin);
setWinPay(winPay);
setHopper(hopper);
setOddsJackpot(oddsJackpot);
setOddsWin(oddsWin);
}
public SlotMachine(String name, double hopper, int oddsJackpot, double jackpotPay, int oddsWin, double winPay) {
setName(name);
setHopper(hopper);
setOddsJackpot(oddsJackpot);
setJackpotPay(jackpotPay);
setOddsWin(oddsWin);
setWinPay(winPay);
}
//end constructors
//setters and getters
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public int getNumJackpot() {
return numJackpot;
}
public void setNumJackpot(int numJackpot) {
this.numJackpot = numJackpot;
}
public double getJackpotPay() {
return jackpotPay;
}
public void setJackpotPay(double jackpotPay) {
boolean badInput = false;
while(jackpotPay < 1.00) {
do {
try {
badInput = false;
System.out.println("You cannot set less than $1.00 as the jackpot pay, try again: ");
jackpotPay = scan.nextDouble();
}catch(InputMismatchException e) {
badInput = true;
System.out.println("You entered an invalid value.");
scan.next();
}
}while(badInput);
}
this.jackpotPay = jackpotPay;
}
public int getNumWin() {
return numWin;
}
public void setNumWin(int numWin) {
this.numWin = numWin;
}
public double getWinPay() {
return winPay;
}
public void setWinPay(double winPay) {
boolean badInput = false;
while(winPay < 0.00 || winPay >= jackpotPay) {
do {
try {
badInput = false;
System.out.println("You cannot set a negative value and more than pay of jackpot as the pay of regular win, try again: ");
winPay = scan.nextDouble();
}catch(InputMismatchException e) {
badInput = true;
System.out.println("You entered an invalid value.");
scan.next();
}
}while(badInput);
}
this.winPay = winPay;
}
public double getHopper() {
return hopper;
}
public void setHopper(double hopper) {
boolean badInput = false;
while(hopper <= 0.00) {
do {
try {
badInput = false;
System.out.println("You cannot set a negative value as the hopper, try again: ");
hopper = scan.nextDouble();
}catch(InputMismatchException e) {
badInput = true;
System.out.println("You entered an invalid value.");
scan.next();
}
}while(badInput);
}
this.hopper = hopper;
}
public int getOddsJackpot() {
return oddsJackpot;
}
public void setOddsJackpot(int oddsJackpot) {
boolean badInput = false;
while(oddsJackpot < 0.00) {
do {
try {
badInput = false;
System.out.println("You cannot set a negative value as the odds of jackpot, try again: ");
oddsJackpot = scan.nextInt();
}catch(InputMismatchException e) {
badInput = true;
System.out.println("You entered an invalid value.");
scan.next();
}
}while(badInput);
}
this.oddsJackpot = oddsJackpot;
}
public int getOddsWin() {
return oddsWin;
}
public void setOddsWin(int oddsWin) {
boolean badInput = false;
while(oddsWin < 0 || oddsWin >= oddsJackpot) {
do {
try {
badInput = false;
System.out.println("You cannot set a negative value and more than odds of jackpot as the odds of regular win, try again: ");
oddsWin = scan.nextInt();
}catch(InputMismatchException e) {
badInput = true;
System.out.println("You entered an invalid value.");
scan.next();
}
}while(badInput);
}
this.oddsWin = oddsWin;
}
//end setters and getters
@Override
public String toString() {
DecimalFormat df = new DecimalFormat("$#,###.##");
String result = "Name: " + name + "\n";
result += "Hopper: " + df.format(hopper) + "\n";
result += "Odds of jackpot: 1 / " + oddsJackpot + "\n";
result += "Jackpot pays: " + df.format(jackpotPay) + "\n";
result += "Odds of regular win: 1 / " + oddsWin + "\n";
result += "Regular win pays: " + df.format(winPay) + "\n";
result += "Balance of the machine: " + df.format(balance) + "\n";
result += "The number of jackpots happened: " + numJackpot + "\n";
result += "The number of regular win happened: " + numWin + "\n";
return result;
}//end toString
public void makeSlotMachine() {
boolean badInput = false;
//name
System.out.println("Enter the name of slot machinie: ");
name = scan.next();
setName(name);
//hopper
do {
try {
badInput = false;
System.out.println("Enter how much you want to set as a hopper: ");
hopper = scan.nextDouble();
}catch(InputMismatchException e) {
badInput = true;
System.out.println("You entered an invalid value.");
scan.next();
}
}while(badInput);
setHopper(hopper);
//oddsJackpot
do {
try {
badInput = false;
System.out.println("Enter how often jackpot happens: ");
oddsJackpot = scan.nextInt();
}catch(InputMismatchException e) {
badInput = true;
System.out.println("You entered an invalid value.");
scan.next();
}
}while(badInput);
setOddsJackpot(oddsJackpot);
//jackpotPay
do {
try {
badInput = false;
System.out.println("Enter how much jackpot pays: ");
jackpotPay = scan.nextDouble();
}catch(InputMismatchException e) {
badInput = true;
System.out.println("You entered an invalid value.");
scan.next();
}
}while(badInput);
setJackpotPay(jackpotPay);
//oddsWin
do {
try {
badInput = false;
System.out.println("Enter how often regular payout happens: ");
oddsWin = scan.nextInt();
}catch(InputMismatchException e) {
badInput = true;
System.out.println("You entered an invalid value.");
scan.next();
}
}while(badInput);
setOddsWin(oddsWin);
//winPay
do {
try {
badInput = false;
System.out.println("Enter how much regular payout pays: ");
winPay = scan.nextDouble();
}catch(InputMismatchException e) {
badInput = true;
System.out.println("You entered an invalid value.");
scan.next();
}
}while(badInput);
setWinPay(winPay);
}//end makeSlotMachine
}//end SlotMachine Class