-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuizGame.java
More file actions
65 lines (48 loc) · 2.26 KB
/
QuizGame.java
File metadata and controls
65 lines (48 loc) · 2.26 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
import java.util.Scanner;
public class QuizGame {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
//QUIZ GAME
/*STEPS TO CREATE GAME :
1.Create array of questions
2.Create array of options
3.Array of answers
4.Declare Variables
5.Welcome Message
6.Listing Each question using loop
a.List our options in loop
b.Take a guess from user
c.Check the guess of user (right or wrong)
7.Display final score*/
String[] questions = {"\nQ1.What is the main function of a router?",
"\nQ2.Which part of the computer is considered the brain?",
"\nQ3.What year was facebook launched? ",
"\nQ4.Who is known as the father of computers?",
"\nQ5.What was the first programming language?"};
String[][] options = {{"1.Storing files","2.Encrypting data","3.Directing internet traffic","4.Managing passwords"},
{"1.CPU","2.Hard Drive","3.RAM","4.GPU"},
{"1.2000","2.2004","3.2006","4.2008"},
{"1.Steve Jobs","2.Bill Gates","3.Alan Turing","4.Charles Babbage"},
{"1.COBOl","2.C","3.Fortran","4.Assembly"}};
int[] answers = {3,1,2,4,3};
int score=0,guess,count=0;
System.out.println("****WELCOME TO THE QUIZ GAME****");
for(int i=0;i<questions.length;i++){
System.out.println(questions[i]);
for(String option : options[i]){
System.out.println(option);
}
System.out.print("\nEnter your answer(1-4) : ");
guess = scanner.nextInt();
if(guess==answers[i]){
System.out.println("CORRECT!");
count++;
}
else{
System.out.println("WRONG!");
}
}
System.out.printf("\nYou scored %d out of 5!",count);
scanner.close();
}
}