-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLotto.java
More file actions
314 lines (300 loc) · 10.3 KB
/
Copy pathLotto.java
File metadata and controls
314 lines (300 loc) · 10.3 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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
package school;
import java.io.IOException;
import java.util.Random;
import java.util.Scanner;
public class Lotto {
public static void main(String[] args) throws IOException {
Scanner input = new Scanner(System.in);
Random rand=new Random();
//
double bank=50;
//
String replay = "";
int check, winning_numbers, num1 = 5, num2 = 30, num3 = 500 , num4 = 100000, num5 = 1000000, num6 = 30000000;
int guess1, guess2 , guess3, guess4, guess5, guess6, hold;
System.out.println(".____ __ __ ________ _____ _______ \r\n" +
"| | _____/ |__/ |_ ____ / _____/ / | | \\ _ \\ \r\n" +
"| | / _ \\ __\\ __\\/ _ \\ / __ \\ / | |_/ /_\\ \\ \r\n" +
"| |__( <_> ) | | | ( <_> ) \\ |__\\ \\/ ^ /\\ \\_/ \\\r\n" +
"|_______ \\____/|__| |__| \\____/ \\_____ /\\____ | \\_____ /\r\n" +
" \\/ \\/ |__| \\/ ");
System.out.println("You started with $"+bank+" in your bank account\nEach play costs $5");
System.out.print("Would you like to buy a ticket? (Y/N): ");
while(true) {
String start = input.next();
if (start.equalsIgnoreCase("y")) {
System.out.println("Processed to next game");
bank -= 5;
System.out.println("");
break;
}
else if (start.equalsIgnoreCase("n")) {
System.out.println("If you don't want to buy a ticket, why run this program?");
replay = "n";
break;
}
else {
System.out.print("Please only type 'y' for yes and 'n' for no: ");
}
}
// Loop starts
while (!replay.equalsIgnoreCase("n")) {
check = 0;
winning_numbers = 0;
// Creating the numbers
int win1 = (int) (Math.random() * 49 + 1);
int win2 = (int) (Math.random() * 49 + 1);
int win3 = (int) (Math.random() * 49 + 1);
int win4 = (int) (Math.random() * 49 + 1);
int win5 = (int) (Math.random() * 49 + 1);
int win6 = (int) (Math.random() * 49 + 1);
// Checking for duplicates
while (win2 == win1) {
win2 = (int) (Math.random() * 49 + 1);
}
while (win3 == win2 || win3 == win1) {
win3 = (int) (Math.random() * 49 + 1);
}
while (win4 == win3 || win4 == win2 || win4 == win1) {
win4 = (int) (Math.random() * 49 + 1);
}
while (win5 == win4 || win5 == win3 || win5 == win2 || win5 == win1) {
win5 = (int) (Math.random() * 49 + 1);
}
while (win6 == win5 || win6 == win4 || win6 == win3 || win6 == win2 || win6 == win1) {
win6 = (int) (Math.random() * 49 + 1);
}
//Sorting the winning numbers
for (int x = 1; x <= 5; x++){
if(win1 > win2){
hold = win1;
win1 = win2;
win2 = hold;
}
if(win2 > win3){
hold = win2;
win2 = win3;
win3 = hold;
}
if(win3 > win4){
hold = win3;
win3 = win4;
win4 = hold;
}if(win4 > win5){
hold = win4;
win4 = win5;
win5 = hold;
}if(win5 > win6){
hold = win5;
win5 = win6;
win6 = hold;
}
}
//Cheat
System.out.println("For testing purposes, here are the winning numbers");
System.out.println("These numbers reset each game!");
System.out.println(win1 + "\t" + win2 + "\t" + win3 + "\t" + win4 + "\t" + win5 + "\t" + win6);
System.out.println("-------------------------------------");
// User guesses
System.out.println("Please enter your six numbers(No repeating numbers or numbers over 49 or under 1) ");
System.out.print("First Number : ");
guess1 = input.nextInt();
while (guess1 < 1 || guess1 > 49){
System.out.print("NUMBERS 1-49 ONLY!! First Number: ");
guess1 = input.nextInt();
}
System.out.print("Second Number: ");
guess2 = input.nextInt();
while (guess2 == guess1 || guess2 < 1 || guess2 > 49) {
if (guess2 == guess1) {
System.out.print("NO REPEATING NUMBERS!! Second Number: ");
}
else{
System.out.print("NUMBERS 1-49 ONLY!! Second Number: ");
}
guess2 = input.nextInt();
}
System.out.print("Third Number : ");
guess3 = input.nextInt();
while (guess3 == guess2 || guess3 == guess1 || guess3 < 1 || guess3 > 49) {
if (guess3 == guess2 || guess3 == guess1) {
System.out.print("NO REPEATING NUMBERS!! Third Number: ");
}
else{
System.out.print("NUMBERS 1-49 ONLY!! Third Number: ");
}
guess3 = input.nextInt();
}
System.out.print("Fourth Number: ");
guess4 = input.nextInt();
while (guess4 == guess3 || guess4 == guess2 || guess4 == guess1 || guess4 < 1 || guess4 > 49) {
if (guess4 == guess3 || guess4 == guess2 || guess4 == guess1) {
System.out.print("NO REPEATING NUMBERS!! Fourth Number: ");
}
else{
System.out.print("NUMBERS 1-49 ONLY!! Fourth Number: ");
}
guess4 = input.nextInt();
}
System.out.print("Fifth Number : ");
guess5 = input.nextInt();
while (guess5 == guess4 || guess5 == guess3 || guess5 == guess2 || guess5 == guess1 || guess5 < 1 || guess5 > 49) {
if (guess5 == guess4 || guess5 == guess3 || guess5 == guess2 || guess5 == guess1) {
System.out.print("NO REPEATING NUMBERS!! Fifth Number: ");
}
else{
System.out.print("NUMBERS 1-49 ONLY!! Fifth Number: ");
}
guess5 = input.nextInt();
}
System.out.print("Sixth Number : ");
guess6 = input.nextInt();
while (guess6 == guess5 || guess6 == guess4 || guess6 == guess3 || guess6 == guess2 || guess6 == guess1 || guess6 < 1 || guess6 > 49) {
if (guess6 == guess5 || guess6 == guess4 || guess6 == guess3 || guess6 == guess2 || guess6 == guess1) {
System.out.print("NO REPEATING NUMBERS!! Sixth Number: ");
}
else{
System.out.print("NUMBERS 1-49 ONLY!! Sixth Number: ");
}
guess6 = input.nextInt();
}
System.out.println("");
//Sorting the guess numbers
for (int i = 1; i <= 5; i++){
if(guess1 > guess2){
hold = guess1;
guess1 = guess2;
guess2 = hold;
}
if(guess2 > guess3){
hold = guess2;
guess2 = guess3;
guess3 = hold;
}
if(guess3 > guess4){
hold = guess3;
guess3 = guess4;
guess4 = hold;
}if(guess4 > guess5){
hold = guess4;
guess4 = guess5;
guess5 = hold;
}if(guess5 > guess6){
hold = guess5;
guess5 = guess6;
guess6 = hold;
}
}
//Displaying the guess numbers
System.out.println( "Your numbers are: "+ guess1 + "\t" + guess2 + "\t" + guess3 + "\t" + guess4 + "\t" + guess5 + "\t" + guess6);
//Checking for winning numbers
//generate lotto pot
double lottopot = rand.nextInt(10000000) + 400000;
if (guess1 == win1 || guess1 == win2 || guess1 == win3 || guess1 == win4 || guess1 == win5 || guess1 == win6){
winning_numbers++;
}
if (guess2 == win1 || guess2 == win2 || guess2 == win3 || guess2 == win4 || guess2 == win5 || guess2 == win6){
winning_numbers++;
}
if (guess3 == win1 || guess3 == win2 || guess3 == win3 || guess3 == win4 || guess3 == win5 || guess3 == win6){
winning_numbers++;
}
if (guess4 == win1 || guess4 == win2 || guess4 == win3 || guess4 == win4 || guess4 == win5 || guess4 == win6){
winning_numbers++;
}
if (guess5 == win1 || guess5 == win2 || guess5 == win3 || guess5 == win4 || guess5 == win5 || guess5 == win6){
winning_numbers++;
}
if (guess6 == win1 || guess6 == win2 || guess6 == win3 || guess6 == win4 || guess6 == win5 || guess6 == win6){
winning_numbers++;
}
System.out.println("The winning numbers are: " + win1 + "\t" + win2 + "\t" + win3 + "\t" + win4 + "\t" + win5 + "\t" + win6);
//Giving the prizes
System.out.println("You got " + winning_numbers + " numbers correct");
System.out.println("There are $" + lottopot + " in the prize pool");
System.out.println("-------------------------------------");
//
double prize=0;
if (winning_numbers == 6) {
prize = (int) (lottopot * 0.8);
} else if (winning_numbers == 5) {
prize = (int) (lottopot * 0.008);
} else if (winning_numbers == 4) {
prize = (int) (lottopot * 0.003);
} else if (winning_numbers == 3) {
prize = (int) (lottopot * 0.001);
} else if (winning_numbers == 2) {
prize = (int) (lottopot * 0.000002);
} else {
System.out.println("You must win 2+ numbers to get a prize!");
}
if (winning_numbers >= 2) {
System.out.println("Your total prize is $" + prize);
bank+=prize;
}
if (winning_numbers>=3) {
System.out.println("You need to pay tax! 30% of your winnings!");
bank-=prize*0.3;
System.out.println("That is $"+prize*0.3);
}
System.out.println("You currently have $"+(int)bank+" in your bank account");
System.out.println("");
//Play Again Prompt
if (bank >= 5){
System.out.print("Would you like to play again?(Y/N): ");
while(true) {
String playresponse = input.nextLine();
if (playresponse.equalsIgnoreCase("y")) {
if (bank >= 5){
System.out.println("OK");
bank -= 5;
break;
}
else{
System.out.println("You don't have enough money");
check = 1;
replay = "n";
System.out.print("Please visit this website to stop gambling\nhttp://www.gamblersanonymous.org/ga/");
}
} else if (playresponse.equalsIgnoreCase("n")) {
System.out.println("Very Well");
replay = "n";
check = 1;
System.out.print("Would you like to donate to charity? (Y/N)");
while(true) {
String charity = input.nextLine();
if (charity.equalsIgnoreCase("y")) {
System.out.println("OK");
System.out.print("Enter the amount of money to be donated(Bank = $"+bank+ "): ");
while (true){
int donate = input.nextInt();
if (donate <= bank) {
System.out.println("You have donated $"+donate+" to charity");
break;
}
else {
System.out.print("You can't donate that amount of money, please re-enter an amount less than your bank amount: ");
}
}
break;
}
else if (charity.equalsIgnoreCase("n")) {
System.out.println("Very Well");
break;
}
else {
System.out.print("Please only type 'y' for yes and 'n' for no: ");
}
}
}
}
}
else{
System.out.println("You don't have enough money to continue playing");
replay = "n";
System.out.print("Please visit this website to stop gambling\nhttp://www.gamblersanonymous.org/ga/");
break;
}
}
}
}