-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuiz.java
668 lines (636 loc) · 33 KB
/
Quiz.java
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
/* This is a computer project.
* Topic: A Quizing Program using Java
* By:Khushi Sabarad
* Class:10
* Hope you like it... */
import java.util.*;
class Quiz
//the class is declared and named Quiz
{//opening of class
public static void main(String args[])
//main static method is declared
{//opening of main method
Scanner sc=new Scanner(System.in);
//to take input from the user
int i,k=0,a,continu=1;
String MemList[][]=new String[10][4];
//A double-dimensional array is used to store the members and their details at quiz masters' paradise.
System.out.println("@@@@Welcome to the Quizz Masters' Paradise!!!@@@");
System.out.println("*********************************************************************************");
// the heading of the program.
System.out.println("Enter 1 if you are an existing member and 2 if you want to be a member.");
int mem=sc.nextInt();
MemList[1][0]="Khushi";//registered name
MemList[1][1]="01/09/2002";//dob
MemList[1][2]="[email protected]";//email
MemList[1][3]="***";//password
/** MemList[2][0]=" ";
MemList[2][1]=" ";
MemList[2][2]=" ";
MemList[2][3]=" ";
MemList[3][0]=" ";
MemList[3][1]=" ";
MemList[3][2]=" ";
MemList[3][3]=" ";
MemList[4][0]= " ";
MemList[4][1]=" ";
MemList[4][2]=" ";
MemList[4][3]=" ";
MemList[5][0]=" ";
MemList[5][1]=" ";
MemList[5][2]=" ";
MemList[5][3]=" "; */
//details of various members are stored
switch(mem)
//switch-case is used to check if the member is existing or has to register.
{
case 1:
//program if the user is already registered.
{//case 1 block opens
System.out.println("Please enter your registered name");
String name=sc.next();
for(i=0;i<MemList.length;i++)
//loop is used to check if the entered name exists in the list of registered members.
{//loop block opens
if(name.equalsIgnoreCase(MemList[i][0]))
{
k=1;
//a variable is used to keep record of the answer produced by if-else so the answer isn't printed numerous times
break;
}
else
k=2;
}//end of for loop block
if(k==1)
{//the result from if-else is printed
System.out.println("Enter your password");
String password=sc.next();
if(password.equals(MemList[i][3]))
System.out.println("***********WELCOME***********");
else
{
System.out.println("Your username password combination does not matched. Please enter your password again.");
System.out.println("Enter your password");
password=sc.next();
}
}//if-else closed
if(k==2)
{//if-else opened
System.out.println("You are not a member. Please register."); //registration begins
System.out.println("Please enter your name.");
name=sc.next();
MemList[0][0]=name;
System.out.println("Please enter your date of birth.[DD/MM/YYYY]");
String dob=sc.next();
MemList[0][1]=dob;
System.out.println("Enter your email id so that we can send you information about recent updates at Quiz Masters' Paradise.");
String email=sc.next();
MemList[0][2]=email;
System.out.println("Enter a password.");
String pass=sc.next();
System.out.println("Enter your password again.");
String password=sc.next();
if(!password.equals(pass))
{//inner if opened
System.out.println("Your password combination did not match.Please retry.");
System.out.println("Enter a password.");
pass=sc.next();
System.out.println("Enter your password again.");
password=sc.next();
}//inner if closed
if(password.equals(pass))
{
MemList[0][3]=password;
System.out.println("Congratulations! You are successfully registered.");
}
}
}//case 1 block is closed
break;
case 2:
//case to start registration
{//case 2 block opens
System.out.println('\f');
//escape sequence to clear the screen for rest of the program
System.out.println("@@@@Welcome to the Registration zone at Quizz Master's Paradise!!!@@@");
System.out.println("*********************************************************************************");
//registration begins here
System.out.println("Please enter your name.");
String name=sc.next();
MemList[1][0]=name;
System.out.println("Please enter your date of birth.[DD/MM/YYYY]");
String dob=sc.next();
MemList[1][1]=dob;
System.out.println("Enter your email id so that we can send you information about recent updates at Quiz Masters' Paradise.");
String email=sc.next();
MemList[1][2]=email;
System.out.println("Enter a password.");
String pass=sc.next();
System.out.println("Enter your password again.");
String password=sc.next();
if(!password.equals(pass))
{
System.out.println("Your password combination did not match.Please retry.");
System.out.println("Enter a password.");
pass=sc.next();
System.out.println("Enter your password again.");
password=sc.next();
}
if(password.equals(pass))
{
MemList[1][3]=password;
System.out.println("Congratulations! You are successfully registered.");
System.out.println("_______________________________________________________________________________________");
}
}//end of case 2 block
} //end of switch block
while(continu!=0)
{
System.out.println("Enter:\n 1 to through the instructions\n 2 to start quizzing\n 3 to quit.");
a=sc.nextInt();
switch (a)
//switch-case to move according to the user's choice of quizzing or quiting
{//switch-block opens
case 1:
//case to print the rules
{//case 1 opens
System.out.println("\f");
System.out.println("$$$$$Quizz Masters' Paradise$$$$$ \n INSTRUCTIONS:");
System.out.println("1.Select the subject you want to be quizzed from.");
System.out.println("2.You will be asked 5 questions from the subject.");
System.out.println("3.Read the question and enter the right OPTION from the 3 choices given.");
System.out.println("4.Each correct answer gives you 1 point.");
System.out.println(" There is no negative marking for incorrect answer.");
System.out.println(" Hope you enjoy quizzing!!\n All the best!!");
System.out.println();
System.out.println("Do you want to start quizzing? \n If yes enter 'Y' or enter 'N'");
String selection=sc.next();
if(selection.equalsIgnoreCase("n"))
break;
else
System.out.println("\f");
}//case 1 closes and the instructions are printed
case 2:
//case if the user wants to quiz
{ //case 1 block opens
System.out.println('\f');//to clear the screen
System.out.println("@@@@Welcome to the Quizz Master's Paradise!!!@@@ \n Let's check your Intelligence");
System.out.println("*********************************************************************************");
System.out.println("Choose a Category");
System.out.println("1.Science \n2.Sports \n3.Geography \n4.General Knowledge\n5.Novels");
int category=sc.nextInt();
//choice of subject to be quizzed from is accepted
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.println('\f');
System.out.println("$$$$$$Quizz Master's Paradise!!!$$$$$$\n IT\'S TIME TO QUIZ!!\n Let's check your Intelligence");
System.out.println("*********************************************************************************");
switch(category)
//switch-case for the choice of subjects
{//switch block opens
case 1:
//science category
{//case block opens
int score=0;
System.out.println("CATEGORY:Science");
System.out.println("Q.1. Who was the first man to go to space?");
System.out.println("A.Yuri Gagarin");
System.out.println("B.Rakesh Sharma ");
System.out.println("C.Neil Armstrong");
String b=sc.next();
if(b.equalsIgnoreCase("A"))//the right answer
{
System.out.println("Your answer is CORRECT");
score++;
}
else//for the wrong answers
System.out.println("Your answer is INCORRECT.The correct answer was A.Yuri Gagarin");
System.out.println();
System.out.println("Q.2.Where in your body is patella?");
System.out.println("A.Elbow");
System.out.println("B.Knee");
System.out.println("C.Head");
String c=sc.next();
if(c.equalsIgnoreCase("B"))//the right answer
{
System.out.println("Your answer is CORRECT");
score++;
}
else//for the wrong answers
System.out.println("Your answer is INCORRECT.The correct answer was B.Knee");
System.out.println();
System.out.println("Q.3.Which is the largest lymphatic organ in the body?");
System.out.println("A.Spleen");
System.out.println("B.Gall Bladder");
System.out.println("C.Liver");
String d=sc.next();
if(d.equalsIgnoreCase("A"))//the right answer
{
System.out.println("Your answer is CORRECT");
score++;
}
else//for the wrong answers
System.out.println("Your answer is INCORRECT.The correct answer was A.Spleen");
System.out.println();
System.out.println("Q.4.How many bones are present in human body?");
System.out.println("A.180");
System.out.println("B.206");
System.out.println("C.212");
String e=sc.next();
if(e.equalsIgnoreCase("B"))//the right answer
{
System.out.println("Your answer is CORRECT");
score++;
}
else//for the wrong answers
System.out.println("Your answer is INCORRECT.The correct answer was B.206");
System.out.println();
System.out.println("Q.5.Triton is the largest satellite of which planet??");
System.out.println("A.Jupiter");
System.out.println("B.Uranus");
System.out.println("C.Neptune");
String f=sc.next();
if(f.equalsIgnoreCase("C"))//the right answer
{
System.out.println("Your answer is CORRECT");
score++;
}
else//for the wrong answers
System.out.println("Your answer is INCORRECT.The correct answer was C.Neptune");
System.out.println("############################################################################");
System.out.println("You got "+score+" out of 5 answers correct");
if(score==0)
System.out.println("Your knowledge in the subject is poor");
else if(score==1)
System.out.println("Your knowledge in the subject is average");
else if(score==2)
System.out.println("Your knowledge in the subject is fair");
else if(score==3)
System.out.println("Your knowledge in the subject is good");
else if(score==4)
System.out.println("Your knowledge in the subject is very good");
else
System.out.println("Your knowledge in the subject is excellent");
}//case 1 is closed
break;
case 2:
//sports category
{//case block opens
int score=0;
System.out.println("CATEGORY:Sports");
System.out.println("Q.1.How many players play in a Basketball team?");
System.out.println("A.9");
System.out.println("B.11");
System.out.println("C.5");
String h=sc.next();
if(h.equalsIgnoreCase("C"))//the right answer
{
System.out.println("Your answer is CORRECT");
score++;
}
else//for the wrong answers
System.out.println("Your answer is INCORRECT.The correct answer was C.5");
System.out.println();
System.out.println("Q.2.Football was originated in which country?");
System.out.println("A.China");
System.out.println("B.India");
System.out.println("C.Japan");
String g=sc.next();
if(g.equalsIgnoreCase("A"))//the right answer
{
System.out.println("Your answer is CORRECT");
score++;
}
else
System.out.println("Your answer is INCORRECT.The correct answer was A.China");
System.out.println();
System.out.println("Q.3.Three events make this sport?");
System.out.println("A.Decathlon");
System.out.println("B.Triathlon");
System.out.println("C.Marathon");
String j=sc.next();
if(j.equalsIgnoreCase("B"))//the right answer
{
System.out.println("Your answer is CORRECT");
score++;
}
else//for the wrong answers
System.out.println("Your answer is INCORRECT.The correct answer was B.Triathlon");
System.out.println();
System.out.println("Q.4. 2010 Commonwealth games was held at?");
System.out.println("A.India");
System.out.println("B.London");
System.out.println("C.Canada");
String m=sc.next();
if(m.equalsIgnoreCase("A"))//the right answer
{
System.out.println("Your answer is CORRECT");
score++;
}
else//for the wrong answers
System.out.println("Your answer is INCORRECT.The correct answer was A.India");
System.out.println();
System.out.println("Q.5.What is the minimum number of points needed to win a tie-break in tennis?");
System.out.println("A.3");
System.out.println("B.5");
System.out.println("C.7");
String l=sc.next();
if(l.equalsIgnoreCase("C"))//the right answer
{
System.out.println("Your answer is CORRECT");
score++;
}
else//for the wrong answers
System.out.println("Your answer is INCORRECT.The correct answer was C.7");
System.out.println("############################################################################");
System.out.println("You got "+score+" out of 5 answers correct");
if(score==0)
System.out.println("Your knowledge in the subject is poor");
else if(score==1)
System.out.println("Your knowledge in the subject is average");
else if(score==2)
System.out.println("Your knowledge in the subject is fair");
else if(score==3)
System.out.println("Your knowledge in the subject is good");
else if(score==4)
System.out.println("Your knowledge in the subject is very good");
else
System.out.println("Your knowledge in the subject is excellent");
}//case 2 is closed
break;
case 3:
//geography category
{//case block opens
int score=0;
System.out.println("CATEGORY:Geography");
System.out.println("Q.1.In which state is Silent Valley?");
System.out.println("A.Kerala");
System.out.println("B.Kashmir");
System.out.println("C.Himachal Pradesh");
String g=sc.next();
if(g.equalsIgnoreCase("A"))//the right answer
{
System.out.println("Your answer is CORRECT");
score++;
}
else//for the wrong answers
System.out.println("Your answer is INCORRECT.The correct answer was A.Kerala");
System.out.println();
System.out.println("Q.2.Which Indian State has the longest canal in the world?");
System.out.println("A.West Bengal");
System.out.println("B.Assam");
System.out.println("C.Rajasthan");
String h=sc.next();
if(h.equalsIgnoreCase("C"))//the right answer
{
System.out.println("Your answer is CORRECT");
score++;
}
else
System.out.println("Your answer is INCORRECT.The correct answer was C.Rajasthan");
System.out.println();
System.out.println("Q.3.Giza is situated on the west bank of which river?");
System.out.println("A.Nile");
System.out.println("B.Amazon");
System.out.println("C.Mississippi");
String j=sc.next();
if(j.equalsIgnoreCase("A"))//the right answer
{
System.out.println("Your answer is CORRECT");
score++;
}
else//for the wrong answers
System.out.println("Your answer is INCORRECT.The correct answer was A.Nile");
System.out.println();
System.out.println("Q.4.The largest freshwater lake in India?");
System.out.println("A.Dal lake");
System.out.println("B.Wular lake");
System.out.println("C.Chilika lake");
String m=sc.next();
if(m.equalsIgnoreCase("B"))//the right answer
{
System.out.println("Your answer is CORRECT");
score++;
}
else//for the wrong answers
System.out.println("Your answer is INCORRECT.The correct answer was B.Wular lake");
System.out.println();
System.out.println("Q.5.Shillong Peak is the highest point of which state?");
System.out.println("A.Assam");
System.out.println("B.Meghalaya");
System.out.println("C.Sikkim");
String l=sc.next();
if(l.equalsIgnoreCase("B"))//the right answer
{
System.out.println("Your answer is CORRECT");
score++;
}
else//for the wrong answers
System.out.println("Your answer is INCORRECT.The correct answer was B.Sikkim");
System.out.println("############################################################################");
System.out.println("You got "+score+" out of 5 answers correct");
if(score==0)
System.out.println("Your knowledge in the subject is poor");
else if(score==1)
System.out.println("Your knowledge in the subject is average");
else if(score==2)
System.out.println("Your knowledge in the subject is fair");
else if(score==3)
System.out.println("Your knowledge in the subject is good");
else if(score==4)
System.out.println("Your knowledge in the subject is very good");
else
System.out.println("Your knowledge in the subject is excellent");
}//case 3 is closed
break;
case 4:
//general knowledge category
{//case block opens
int score=0;
System.out.println("CATEGORY:General Knowledge");
System.out.println("Q.1.Who is the CEO of Tesla?");
System.out.println("A.Tim Cook");
System.out.println("B.Elon Musk");
System.out.println("C.Greg Brown");
String g=sc.next();
if(g.equalsIgnoreCase("B"))//the right answer
{
System.out.println("Your answer is CORRECT");
score++;
}
else//for the wrong answers
System.out.println("Your answer is INCORRECT.The correct answer was B.Elon Musk");
System.out.println();
System.out.println("Q.2.The AIBO robotic pets are designed by which company?");
System.out.println("A.Apple");
System.out.println("B.Samsung");
System.out.println("C.Sony");
String h=sc.next();
if(h.equalsIgnoreCase("C"))//the right answer
{
System.out.println("Your answer is CORRECT");
score++;
}
else
System.out.println("Your answer is INCORRECT.The correct answer was C.Sony");
System.out.println();
System.out.println("Q.3.Entomology is the science that studies...");
System.out.println("A.Insects");
System.out.println("B.Formation of rocks");
System.out.println("C.Human behaviour");
String j=sc.next();
if(j.equalsIgnoreCase("A"))//the right answer
{
System.out.println("Your answer is CORRECT");
score++;
}
else//for the wrong answers
System.out.println("Your answer is INCORRECT.The correct answer was A.Insects");
System.out.println();
System.out.println("Q.4. Which planet has approximately the same landmass as Earth?");
System.out.println("A.Mercury");
System.out.println("B.Venus");
System.out.println("C.Mars");
String m=sc.next();
if(m.equalsIgnoreCase("C"))//the right answer
{
System.out.println("Your answer is CORRECT");
score++;
}
else//for the wrong answers
System.out.println("Your answer is INCORRECT.The correct answer was C.Mars");
System.out.println();
System.out.println("Q.5.When is the World Population Day observed?");
System.out.println("A.September 16");
System.out.println("B.July 11");
System.out.println("C.April 7");
String l=sc.next();
if(l.equalsIgnoreCase("B"))//the right answer
{
System.out.println("Your answer is CORRECT");
score++;
}
else//for the wrong answers
System.out.println("Your answer is INCORRECT.The correct answer was B.July 11");
System.out.println("############################################################################");
System.out.println("You got "+score+" out of 5 answers correct");
if(score==0)
System.out.println("Your knowledge in the subject is poor");
else if(score==1)
System.out.println("Your knowledge in the subject is average");
else if(score==2)
System.out.println("Your knowledge in the subject is fair");
else if(score==3)
System.out.println("Your knowledge in the subject is good");
else if(score==4)
System.out.println("Your knowledge in the subject is very good");
else
System.out.println("Your knowledge in the subject is excellent");
}//case 4 is closed
break;
case 5:
//novels category
{//case block opens
int score=0;
System.out.println("CATEGORY:Novels");
System.out.println("Q.1.What is the moto of Hogwarts School of Witchcraft and Wizardy?");
System.out.println("A.Swish and Flick");
System.out.println("B.Never Tickle A Sleeping Dragon");
System.out.println("C.Never fear a boggart");
String g=sc.next();
if(g.equalsIgnoreCase("B"))//the right answer
{
System.out.println("Your answer is CORRECT");
score++;
}
else//for the wrong answers
System.out.println("Your answer is INCORRECT.The correct answer was B.Never Tickle A Sleeping Dragon");
System.out.println();
System.out.println("Q.2.Katniss Everdeen was from which district?");
System.out.println("A.District 4");
System.out.println("B.District 8");
System.out.println("C.District 12");
String h=sc.next();
if(h.equalsIgnoreCase("C"))//the right answer
{
System.out.println("Your answer is CORRECT");
score++;
}
else
System.out.println("Your answer is INCORRECT.The correct answer was C.District 12");
System.out.println();
System.out.println("Q.3.Who is the Author of Percy Jackson novel series?");
System.out.println("A.Rick Riordan");
System.out.println("B.J.K.Rowling");
System.out.println("C.Rick Yancey");
String j=sc.next();
if(j.equalsIgnoreCase("A"))//the right answer
{
System.out.println("Your answer is CORRECT");
score++;
}
else//for the wrong answers
System.out.println("Your answer is INCORRECT.The correct answer was A.Rick Riordan");
System.out.println();
System.out.println("Q.4. Which TV Show is based on the book-The Mortal Instruments?");
System.out.println("A.Riverdale");
System.out.println("B.Shadowhunters");
System.out.println("C.Stranger Things");
String m=sc.next();
if(m.equalsIgnoreCase("B"))//the right answer
{
System.out.println("Your answer is CORRECT");
score++;
}
else//for the wrong answers
System.out.println("Your answer is INCORRECT.The correct answer was B.Shadowhunters");
System.out.println();
System.out.println("Q.5.Who was the Cursed Child?");
System.out.println("A.Albus Potter");
System.out.println("B.Scorpius Malfoy");
System.out.println("C.Delphini");
String l=sc.next();
if(l.equalsIgnoreCase("A"))//the right answer
{
System.out.println("Your answer is CORRECT");
score++;
}
else//for the wrong answers
System.out.println("Your answer is INCORRECT.The correct answer was A.Albus Potter");
System.out.println("############################################################################");
System.out.println("You got "+score+" out of 5 answers correct");
if(score==0)
System.out.println("Your knowledge on novels is poor");
else if(score==1)
System.out.println("Your knowledge on novels is average");
else if(score==2)
System.out.println("Your knowledge on novels is fair");
else if(score==3)
System.out.println("Your knowledge on novels is good");
else if(score==4)
System.out.println("Your knowledge on novels is very good");
else
System.out.println("Your knowledge on novels is excellent");
}//case 5 is closed
break;
default:
System.out.println("Please enter correct category.");
} //switch for printing questions ends
System.out.println("***********Thank You for quizzing with us!***********");
System.out.println("Do you want to start quizzing again? \n If yes enter '1' or enter '0'");
continu=sc.nextInt();
if(continu==1)
{
System.out.println("\f");//to clear the screen
}
else if(continu==0)
{
System.out.println("$$$$$$$Thank you for quizzing with us$$$$$$$");
}
}//quizzing ends
break;
case 3:
System.out.println("**********THANK YOU************");
}//end of switch case
}//while loop closes
}//method block closes
}//end of class
//program ends