-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathKBC-quiz.java
More file actions
302 lines (280 loc) · 7.88 KB
/
KBC-quiz.java
File metadata and controls
302 lines (280 loc) · 7.88 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
// Kashish Ahuja - codeitmin
// KBC Quiz
/* Take 10 questions: core java based questions
Two life lines: 50-50, change the question
Show total money won */
import java.util.Scanner;
import static java.lang.System.out;
import static java.lang.System.in;
import javax.swing.JOptionPane;
class KBC
{
static
{
out.println("Welcome to KBC... ");
}
static Scanner sc = new Scanner(in);
public static int check(String userAns, String correctAns, int m)
{
if(userAns.equalsIgnoreCase("FF"))
{
JOptionPane.showMessageDialog(null,"\n50-50 life line activated");
return 2;
}
else if(userAns.equalsIgnoreCase("CTQ"))
{
JOptionPane.showMessageDialog(null,"\nChange the question life line activated");
JOptionPane.showMessageDialog(null,"New Question...");
return 1;
}
else
{
if(userAns.equals(correctAns))
{
JOptionPane.showMessageDialog(null,"\nThat's the right answer.");
if(m!=10)
{
JOptionPane.showMessageDialog(null,"Total money won: Rs " + m +"0 lakh");
return 0;
}
else
{
JOptionPane.showMessageDialog(null,"Total money won: Rs 1Cr");
JOptionPane.showMessageDialog(null,"You are now a CrorePati");
JOptionPane.showMessageDialog(null,"ParttYYY Brroooo");
return 0;
}
}
else
{
JOptionPane.showMessageDialog(null,"\nThat's not the right answer. You lost.");
JOptionPane.showMessageDialog(null,"Total money won: Rs " + (m-1) +"0 lakh");
System.exit(0);
return 0;
}
}
}
public static String lifeLine(boolean ff, boolean ctq)
{
if(ff==true)
{
if(ctq==true)
return "\nLife line: 50-50 : FF, Change the question : CTQ";
else
return "\nLife line: 50-50 : FF";
}
else if(ctq==true)
return "\nLife line: Change the question : CTQ";
else
return "\nLife line: No life lines left";
}
public static void questions()
{
String ans;
int money=0, chk;
boolean ff=true, ctq=true;
ans=JOptionPane.showInputDialog("\nWhich of these is not a phase of Agile approach? \nA) Application Database making \nB) Application Analysis \nC)Application Marketing \nD) Application Launching \n" + lifeLine(ff, ctq));
money++;
chk=check(ans, "C", money);
if(chk==1)
{
money--;
ctq=false;
}
else if(chk==2)
{
ff=false;
ans=JOptionPane.showInputDialog("\nWhich of these is not a phase of Agile approach \nA) \nB) Application Analysis \nC)Application Marketing \nD) \n"+ lifeLine(ff,ctq));
if(check(ans, "C", money)==1)
{
money--;
ctq=false;
}
}
ans=JOptionPane.showInputDialog("\nJava can not be defined as: ? \nA) Annotation programming \nB) Purely object oriented programming \nC) Object oriented programming \n D)Automation oriented programming\n"+ lifeLine(ff,ctq));
money++;
chk=check(ans, "D", money);
if(chk==1)
{
money--;
ctq=false;
}
else if(chk==2)
{
ff=false;
ans=JOptionPane.showInputDialog("\nJava can not be defined as: ? \nA) Annotation programming \nB) \nC) \nD)Automation oriented programming\n"+ lifeLine(ff,ctq));
if(check(ans, "D", money)==1)
{
money--;
ctq=false;
}
}
ans=JOptionPane.showInputDialog("\nJVM is an: ?\nA) Compiler \nB)Interpreter \nC) Both \n D) None\n"+ lifeLine(ff,ctq));
money++;
chk=check(ans, "B", money);
if(chk==1)
{
money--;
ctq=false;
}
else if(chk==2)
{
ff=false;
ans=JOptionPane.showInputDialog("\nJVM is an: ?\nA) Compiler \nB)Interpreter \nC) \nD) \n"+ lifeLine(ff,ctq));
if(check(ans, "B", money)==1)
{
money--;
ctq=false;
}
}
ans=JOptionPane.showInputDialog("\nWhich of these is not a non-access level in java? \nA)Transition \nB) Strictfp \nC) Final \nD) Static\n"+ lifeLine(ff,ctq));
money++;
chk=check(ans, "A", money);
if(chk==1)
{
money--;
ctq=false;
}
else if(chk==2)
{
ff=false;
ans=JOptionPane.showInputDialog("\nWhich of these is not a non-access level in java? \nA)Transition \nB) \nC) Final \nD) \n"+ lifeLine(ff,ctq));
if(check(ans, "A", money)==1)
{
money--;
ctq=false;
}
}
ans=JOptionPane.showInputDialog("\nWhich of these is not a method provided by Scanner class? \nA) nextShort() \nB) nextLine() \nC)nextChar() \nD) nextBoolean()\n"+ lifeLine(ff,ctq));
money++;
chk=check(ans, "C", money);
if(chk==1)
{
money--;
ctq=false;
}
else if(chk==2)
{
ff=false;
ans=JOptionPane.showInputDialog("\nWhich of these is not a method provided by Scanner class? \nA) nextShort() \nB) \nC)nextChar() \nD) \n"+ lifeLine(ff,ctq));
if(check(ans, "C", money)==1)
{
money--;
ctq=false;
}
}
ans=JOptionPane.showInputDialog("\nIn java everything by default is of type? \nA) Public \nB) Private \nC) Protected \nD)Default\n"+ lifeLine(ff,ctq));
money++;
chk=check(ans, "D", money);
if(chk==1)
{
money--;
ctq=false;
}
else if(chk==2)
{
ff=false;
ans=JOptionPane.showInputDialog("\nIn java everything by default is of type?\nA) Public \nB) \nC) \nD)Default\n"+ lifeLine(ff,ctq));
if(check(ans, "D", money)==1)
{
money--;
ctq=false;
}
}
ans=JOptionPane.showInputDialog("\nWhich of these is not a way of importing packages?\nA)Runtime \nB) Global \nC) Static \n D) Non-static\n"+ lifeLine(ff,ctq));
money++;
chk=check(ans, "A", money);
if(chk==1)
{
money--;
ctq=false;
}
else if(chk==2)
{
ff=false;
ans=JOptionPane.showInputDialog("\nWhich of these is not a way of importing packages?\nA)Runtime \nB) Global \nC) \n D) \n"+ lifeLine(ff,ctq));
if(check(ans, "A", money)==1)
{
money--;
ctq=false;
}
}
ans=JOptionPane.showInputDialog("\nWhich of these is a way of identifying an object in java?\nA) classname name \nB)new classname \nC) uppercase \n D) datatype name\n"+ lifeLine(ff,ctq));
money++;
chk=check(ans, "B", money);
if(chk==1)
{
money--;
ctq=false;
}
else if(chk==2)
{
ff=false;
ans=JOptionPane.showInputDialog("\nWhich of these is a way of identifying an object in java?\nA) classname name \nB)new classname \nC) \n D)\n"+ lifeLine(ff,ctq));
if(check(ans, "B", money)==1)
{
money--;
ctq=false;
}
}
ans=JOptionPane.showInputDialog("\nWhich of these java classes does not contain format() method?\nA) String \nB) DateFormat \nC)LocalDateFormat \nD) NumberFormat\n"+ lifeLine(ff,ctq));
money++;
chk=check(ans, "C", money);
if(chk==1)
{
money--;
ctq=false;
}
else if(chk==2)
{
ff=false;
ans=JOptionPane.showInputDialog("\nWhich of these java classes does not contain format() method?\nA) \nB) \nC)LocalDateFormat \nD) NumberFormat\n"+ lifeLine(ff,ctq));
if(check(ans, "C", money)==1)
{
money--;
ctq=false;
}
}
ans=JOptionPane.showInputDialog("\nWhat is the correct output of DateFormat class with LONG static constant?\nA) 8/17/21 \nB)August 17, 2021 \nC) Tuesday, August, 17, 2021 \nD) Aug 17, 2021\n"+ lifeLine(ff,ctq));
money++;
chk=check(ans, "B", money);
if(chk==1)
{
money--;
ctq=false;
}
else if(chk==2)
{
ff=false;
ans=JOptionPane.showInputDialog("\nWhat is the correct output of DateFormat class with LONG static constant?\nA) \nB)August 17, 2021 \nC) Tuesday, August, 17, 2021 \n D)\n"+ lifeLine(ff,ctq));
if(check(ans, "B", money)==1)
{
money--;
ctq=false;
}
}
ans=JOptionPane.showInputDialog("\nWhat is these dialog box method does not require null?\nA)showInputDialog() \nB) showMessageDialog() \nC) showConfirmDialog() \nD) showGraphicDialog()\n"+ lifeLine(ff,ctq));
money++;
chk=check(ans, "A", money);
if(chk==1)
{
money--;
ctq=false;
}
else if(chk==2)
{
ff=false;
ans=JOptionPane.showInputDialog("\nWhat is these dialog box method does not require null?\nA)showInputDialog() \nB) \nC) showConfirmDialog() \nD) \n"+ lifeLine(ff,ctq));
if(check(ans, "A", money)==1)
{
money--;
ctq=false;
}
}
}
static public void main(String...args)
{
JOptionPane.showMessageDialog(null, "Welcome to KBC...");
questions();
}
}