-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLottery.java
More file actions
80 lines (75 loc) · 3.36 KB
/
Copy pathLottery.java
File metadata and controls
80 lines (75 loc) · 3.36 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
//**************************************************************
// Lottery.java Author: Luc Barenghien Date: 11/5/2019
// A lottery simulation program that compares user inputted
// values with computer generated ones and outputs outcome.
//**************************************************************
import java.lang.Math;
import java.util.Scanner;
//I had to import the math class and the scanner class because they are used in this program.
public class Lottery
{
public static void main( String[] args )
{
int comp_num1 = (int) (Math.random()*54)+1;
int comp_num2 = (int) (Math.random()*54)+1;
int comp_num3 = (int) (Math.random()*54)+1;
int comp_num4 = (int) (Math.random()*54)+1;
//The while loop below handles scenarios where there are duplicate balls. The while loop will continue to find new numbers until it finds unique numbers.
while (comp_num1 == comp_num2 || comp_num1 == comp_num3 || comp_num1 == comp_num4 || comp_num2 == comp_num1 || comp_num2==comp_num3 || comp_num2 == comp_num4 || comp_num3==comp_num1 || comp_num3==comp_num2 || comp_num3==comp_num4 || comp_num4==comp_num1 || comp_num4==comp_num2 || comp_num4==comp_num3)
{
comp_num1 = (int) (Math.random()*54)+1;
comp_num2 = (int) (Math.random()*54)+1;
comp_num3 = (int) (Math.random()*54)+1;
comp_num4 = (int) (Math.random()*54)+1;
}
Scanner scan = new Scanner(System.in);
System.out.println("Please enter first guess number");
int user_num1 = scan.nextInt();
System.out.println("Please enter a unique second number");
int user_num2 = scan.nextInt();
System.out.println("Please enter a unique third number");
int user_num3 = scan.nextInt();
System.out.println("Please enter a unique fourth number");
int user_num4 = scan.nextInt();
//The section directly below is the counter section. In this section, I used many if statemejnts to compare the values of the user input and the computer generated values to determine how many matching numbers there are (if any).
int counter = 0;
if (user_num1 == comp_num1 || user_num1 == comp_num2 || user_num1 == comp_num3 || user_num1 == comp_num4)
{
counter++;
}
if (user_num2==comp_num1 || user_num2 == comp_num2 || user_num2==comp_num3 || user_num2==comp_num4)
{
counter++;
}
if (user_num3==comp_num1 || user_num3==comp_num2 || user_num3==comp_num3 || user_num3==comp_num4)
{
counter++;
}
if (user_num4==comp_num1 || user_num4==comp_num2 || user_num4==comp_num3 || user_num4==comp_num4)
{
counter++;
}
// That concludes the counter section
//The section below is testing for the different results of the counter "i"
if (counter == 0)
{
System.out.println("You lost");
}
else if (counter == 1)
{
System.out.println("Congratulations! You matched " +counter+ " number! You just won a free ticket");
}
else if (counter == 2)
{
System.out.println("Congratulations! You matched " +counter+ " numbers! You just won $25");
}
else if (counter == 3)
{
System.out.println("Congratulations! You matched " +counter+ " numbers! You just won $1000");
}
else
{
System.out.println("Congratulations! You matched " +counter+ " numbers! You just won $75,000");
}
}
}