Skip to content

Commit b30afe1

Browse files
KBC quiz
1 parent 27e2a03 commit b30afe1

File tree

1 file changed

+302
-0
lines changed

1 file changed

+302
-0
lines changed

KBC-quiz.java

Lines changed: 302 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,302 @@
1+
// Kashish Ahuja - codeitmin
2+
3+
// KBC Quiz
4+
/* Take 10 questions: core java based questions
5+
Two life lines: 50-50, change the question
6+
Show total money won */
7+
8+
import java.util.Scanner;
9+
import static java.lang.System.out;
10+
import static java.lang.System.in;
11+
import javax.swing.JOptionPane;
12+
13+
class KBC
14+
{
15+
static
16+
{
17+
out.println("Welcome to KBC... ");
18+
}
19+
20+
static Scanner sc = new Scanner(in);
21+
22+
public static int check(String userAns, String correctAns, int m)
23+
{
24+
if(userAns.equalsIgnoreCase("FF"))
25+
{
26+
JOptionPane.showMessageDialog(null,"\n50-50 life line activated");
27+
return 2;
28+
}
29+
30+
else if(userAns.equalsIgnoreCase("CTQ"))
31+
{
32+
JOptionPane.showMessageDialog(null,"\nChange the question life line activated");
33+
JOptionPane.showMessageDialog(null,"New Question...");
34+
return 1;
35+
}
36+
37+
else
38+
{
39+
if(userAns.equals(correctAns))
40+
{
41+
JOptionPane.showMessageDialog(null,"\nThat's the right answer.");
42+
if(m!=10)
43+
{
44+
JOptionPane.showMessageDialog(null,"Total money won: Rs " + m +"0 lakh");
45+
return 0;
46+
}
47+
else
48+
{
49+
JOptionPane.showMessageDialog(null,"Total money won: Rs 1Cr");
50+
JOptionPane.showMessageDialog(null,"You are now a CrorePati");
51+
JOptionPane.showMessageDialog(null,"ParttYYY Brroooo");
52+
return 0;
53+
}
54+
}
55+
else
56+
{
57+
JOptionPane.showMessageDialog(null,"\nThat's not the right answer. You lost.");
58+
JOptionPane.showMessageDialog(null,"Total money won: Rs " + (m-1) +"0 lakh");
59+
System.exit(0);
60+
return 0;
61+
}
62+
}
63+
}
64+
65+
public static String lifeLine(boolean ff, boolean ctq)
66+
{
67+
if(ff==true)
68+
{
69+
if(ctq==true)
70+
return "\nLife line: 50-50 : FF, Change the question : CTQ";
71+
else
72+
return "\nLife line: 50-50 : FF";
73+
}
74+
else if(ctq==true)
75+
return "\nLife line: Change the question : CTQ";
76+
else
77+
return "\nLife line: No life lines left";
78+
}
79+
80+
public static void questions()
81+
{
82+
String ans;
83+
int money=0, chk;
84+
boolean ff=true, ctq=true;
85+
86+
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));
87+
money++;
88+
chk=check(ans, "C", money);
89+
if(chk==1)
90+
{
91+
money--;
92+
ctq=false;
93+
}
94+
else if(chk==2)
95+
{
96+
ff=false;
97+
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));
98+
if(check(ans, "C", money)==1)
99+
{
100+
money--;
101+
ctq=false;
102+
}
103+
}
104+
105+
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));
106+
money++;
107+
chk=check(ans, "D", money);
108+
if(chk==1)
109+
{
110+
money--;
111+
ctq=false;
112+
}
113+
else if(chk==2)
114+
{
115+
ff=false;
116+
ans=JOptionPane.showInputDialog("\nJava can not be defined as: ? \nA) Annotation programming \nB) \nC) \nD)Automation oriented programming\n"+ lifeLine(ff,ctq));
117+
if(check(ans, "D", money)==1)
118+
{
119+
money--;
120+
ctq=false;
121+
}
122+
}
123+
124+
ans=JOptionPane.showInputDialog("\nJVM is an: ?\nA) Compiler \nB)Interpreter \nC) Both \n D) None\n"+ lifeLine(ff,ctq));
125+
money++;
126+
chk=check(ans, "B", money);
127+
if(chk==1)
128+
{
129+
money--;
130+
ctq=false;
131+
}
132+
else if(chk==2)
133+
{
134+
ff=false;
135+
ans=JOptionPane.showInputDialog("\nJVM is an: ?\nA) Compiler \nB)Interpreter \nC) \nD) \n"+ lifeLine(ff,ctq));
136+
if(check(ans, "B", money)==1)
137+
{
138+
money--;
139+
ctq=false;
140+
}
141+
}
142+
143+
144+
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));
145+
money++;
146+
chk=check(ans, "A", money);
147+
if(chk==1)
148+
{
149+
money--;
150+
ctq=false;
151+
}
152+
else if(chk==2)
153+
{
154+
ff=false;
155+
ans=JOptionPane.showInputDialog("\nWhich of these is not a non-access level in java? \nA)Transition \nB) \nC) Final \nD) \n"+ lifeLine(ff,ctq));
156+
if(check(ans, "A", money)==1)
157+
{
158+
money--;
159+
ctq=false;
160+
}
161+
}
162+
163+
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));
164+
money++;
165+
chk=check(ans, "C", money);
166+
if(chk==1)
167+
{
168+
money--;
169+
ctq=false;
170+
}
171+
else if(chk==2)
172+
{
173+
ff=false;
174+
ans=JOptionPane.showInputDialog("\nWhich of these is not a method provided by Scanner class? \nA) nextShort() \nB) \nC)nextChar() \nD) \n"+ lifeLine(ff,ctq));
175+
if(check(ans, "C", money)==1)
176+
{
177+
money--;
178+
ctq=false;
179+
}
180+
}
181+
182+
ans=JOptionPane.showInputDialog("\nIn java everything by default is of type? \nA) Public \nB) Private \nC) Protected \nD)Default\n"+ lifeLine(ff,ctq));
183+
money++;
184+
chk=check(ans, "D", money);
185+
if(chk==1)
186+
{
187+
money--;
188+
ctq=false;
189+
}
190+
else if(chk==2)
191+
{
192+
ff=false;
193+
ans=JOptionPane.showInputDialog("\nIn java everything by default is of type?\nA) Public \nB) \nC) \nD)Default\n"+ lifeLine(ff,ctq));
194+
if(check(ans, "D", money)==1)
195+
{
196+
money--;
197+
ctq=false;
198+
}
199+
}
200+
201+
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));
202+
money++;
203+
chk=check(ans, "A", money);
204+
if(chk==1)
205+
{
206+
money--;
207+
ctq=false;
208+
}
209+
else if(chk==2)
210+
{
211+
ff=false;
212+
ans=JOptionPane.showInputDialog("\nWhich of these is not a way of importing packages?\nA)Runtime \nB) Global \nC) \n D) \n"+ lifeLine(ff,ctq));
213+
if(check(ans, "A", money)==1)
214+
{
215+
money--;
216+
ctq=false;
217+
}
218+
}
219+
220+
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));
221+
money++;
222+
chk=check(ans, "B", money);
223+
if(chk==1)
224+
{
225+
money--;
226+
ctq=false;
227+
}
228+
else if(chk==2)
229+
{
230+
ff=false;
231+
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));
232+
if(check(ans, "B", money)==1)
233+
{
234+
money--;
235+
ctq=false;
236+
}
237+
}
238+
239+
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));
240+
money++;
241+
chk=check(ans, "C", money);
242+
if(chk==1)
243+
{
244+
money--;
245+
ctq=false;
246+
}
247+
else if(chk==2)
248+
{
249+
ff=false;
250+
ans=JOptionPane.showInputDialog("\nWhich of these java classes does not contain format() method?\nA) \nB) \nC)LocalDateFormat \nD) NumberFormat\n"+ lifeLine(ff,ctq));
251+
if(check(ans, "C", money)==1)
252+
{
253+
money--;
254+
ctq=false;
255+
}
256+
}
257+
258+
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));
259+
money++;
260+
chk=check(ans, "B", money);
261+
if(chk==1)
262+
{
263+
money--;
264+
ctq=false;
265+
}
266+
else if(chk==2)
267+
{
268+
ff=false;
269+
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));
270+
if(check(ans, "B", money)==1)
271+
{
272+
money--;
273+
ctq=false;
274+
}
275+
}
276+
277+
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));
278+
money++;
279+
chk=check(ans, "A", money);
280+
if(chk==1)
281+
{
282+
money--;
283+
ctq=false;
284+
}
285+
else if(chk==2)
286+
{
287+
ff=false;
288+
ans=JOptionPane.showInputDialog("\nWhat is these dialog box method does not require null?\nA)showInputDialog() \nB) \nC) showConfirmDialog() \nD) \n"+ lifeLine(ff,ctq));
289+
if(check(ans, "A", money)==1)
290+
{
291+
money--;
292+
ctq=false;
293+
}
294+
}
295+
}
296+
297+
static public void main(String...args)
298+
{
299+
JOptionPane.showMessageDialog(null, "Welcome to KBC...");
300+
questions();
301+
}
302+
}

0 commit comments

Comments
 (0)