-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNellQuizMath.java
More file actions
183 lines (149 loc) · 4.95 KB
/
NellQuizMath.java
File metadata and controls
183 lines (149 loc) · 4.95 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
// Wneljae
import java.util.*;
public class NellMathQuiz {
public static void main(String[] args) {
Scanner userInput = new Scanner(System.in);
Random randInt = new Random();
while (true) {
int score = 0;
int level = 0;
// Start
System.out.println("Quiz time! (10 pts each)");
System.out.print("Enter your name: ");
String name = userInput.next();
System.out.print("\n");
System.out.println("1. Easy");
System.out.println("2. Medium");
System.out.println("3. Hard");
System.out.println("4. Extreme");
System.out.print("Choose difficulty: ");
int difInt = userInput.nextInt();
// Switch-case for difficulty chooser
switch (difInt) {
case 1:
level = 10;
break;
case 2:
level = 30;
break;
case 3:
level = 80;
break;
case 4:
level = 1000;
break;
case 5:
level = 1000000;
break;
default:
break;
}
// Questions
// 1
int num1 = randInt.nextInt(level);
int num2 = randInt.nextInt(level);
// 2
int Anum1 = randInt.nextInt(level);
int Anum2 = randInt.nextInt(level);
// 3
int Bnum1 = randInt.nextInt(level);
int Bnum2 = randInt.nextInt(level);
// 4
int Cnum1 = randInt.nextInt(level);
int Cnum2 = randInt.nextInt(level);
// 5
int Dnum1 = randInt.nextInt(level);
int Dnum2 = randInt.nextInt(level);
// Answer identifer
String q1 = "N/A";
String q2 = "N/A";
String q3 = "N/A";
String q4 = "N/A";
String q5 = "N/A";
// Solves the random int
int q1Answer = num1 + num2;
int q2Answer = Anum1 - Anum2;
int q3Answer = Bnum1 * Bnum2;
int q4Answer = Cnum1 + Cnum2;
int q5Answer = Dnum1 - Dnum2;
// Displays the questions
System.out.print("1. " + num1 + " + " + num2 + " = ");
double answer1 = userInput.nextInt();
System.out.print("2. " + Anum1 + " - " + Anum2 + " = ");
double answer2 = userInput.nextInt();
System.out.print("3. " + Bnum1 + " * " + Bnum2 + " = ");
double answer3 = userInput.nextInt();
System.out.print("4. " + Cnum1 + " + " + Cnum2 + " = ");
double answer4 = userInput.nextInt();
System.out.print("5. " + Dnum1 + " - " + Dnum2 + " = ");
double answer5 = userInput.nextInt();
// Condition 1
if (answer1 == q1Answer) {
score += 10;
q1 = "Correct";
} else if (answer1 != q1Answer) {
score += 0;
q1 = "Wrong";
} else {
System.out.print("Unknown answer: " + answer1);
}
// Condition 2
if (answer2 == q2Answer) {
score += 10;
q2 = "Correct";
} else if (answer2 != q2Answer) {
score += 0;
q2 = "Wrong";
} else {
System.out.print("Unknown answer: " + answer2);
}
// Condition 3
if (answer3 == q3Answer) {
score += 10;
q3 = "Correct";
} else if (answer3 != q3Answer) {
score += 0;
q3 = "Wrong";
} else {
System.out.print("Unknown answer: " + answer3);
}
// Condition 4
if (answer4 == q4Answer) {
score += 10;
q4 = "Correct";
} else if (answer4 != q4Answer) {
score += 0;
q4 = "Wrong";
} else {
System.out.print("Unknown answer: " + answer4);
}
// Condition 5
if (answer5 == q5Answer) {
score += 10;
q5 = "Correct";
} else if (answer5 != q5Answer) {
score += 0;
q5 = "Wrong";
} else {
System.out.print("Unknown answer: " + answer5);
}
// Final results
System.out.println(name + "'s test results!: ");
System.out.println("1. " + q1 + " (" + answer1 + ")");
System.out.println("2. " + q2 + " (" + answer2 + ")");
System.out.println("3. " + q3 + " (" + answer3 + ")");
System.out.println("4. " + q4 + " (" + answer4 + ")");
System.out.println("5. " + q5 + " (" + answer5 + ")");
System.out.println("Total score: " + score + " / 50");
// Try again
System.out.print("Try again? Y/N: ");
char confirm = userInput.next().toUpperCase().charAt(0);
if (confirm == 'Y') {
} else if (confirm == 'N') {
break;
} else {
System.out.println("Error: please type the right letter");
}
}
}
}