-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestionServices.java
More file actions
61 lines (51 loc) · 2 KB
/
Copy pathQuestionServices.java
File metadata and controls
61 lines (51 loc) · 2 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
import java.util.Scanner;
public class QuestionServices
{
Question[] questions = new Question[5];
String selection[] = new String[5];
public QuestionServices()
{
questions[0] = new Question(1, "Which is the capital of India ?", "Mumbai", "Chennai", "New Delhi", "Kolkata", "New Delhi");
questions[1] = new Question(2, "Which planet is known as the Red Planet ?", "Venus", "Mars", "Jupiter", "Saturn", "Mars");
questions[2] = new Question(3, "Who is known as the Father of the Nation in India ?", "Jawaharlal Nehru", "Subhas Chandra Bose", "Mahatma Gandhi", "Bhagat Singh", "Mahatma Gandhi");
questions[3] = new Question(4, "How many continents are there in the world ?", "5", "6", "7", "8", "7");
questions[4] = new Question(5, "Which is the largest ocean in the world ?", "Indian Ocean", "Atlantic Ocean", "Arctic Ocean", "Pacific Ocean", "Pacific Ocean");
}
public void playQuiz()
{
int i = 0;
for(Question q : questions)
{
System.out.println("Question no : " + q.getId());
System.out.println(q.getQuestion());
Scanner sc = new Scanner(System.in);
for(String option : q.getOpt())
{
System.out.println(option);
}
System.out.println("");
System.out.print("Enter answer: ");
selection[i] = sc.nextLine();
i++;
}
for(String s : selection)
{
System.out.println("Your answer: " + s);
}
}
public void PrintMarks()
{
int marks = 0;
for(int i = 0; i < questions.length; i++)
{
Question que = questions[i];
String correctAnswer = que.getAnswer();
String userAnswer = selection[i];
if(correctAnswer.equals(userAnswer))
{
marks++;
}
}
System.out.println("Your total marks: " + marks);
}
}