-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestionService.java
More file actions
45 lines (37 loc) · 1.37 KB
/
QuestionService.java
File metadata and controls
45 lines (37 loc) · 1.37 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
import java.util.Scanner;
public class QuestionService {
Question[] questions = new Question[5];
String [] user = new String[5];
public QuestionService(){
questions[0] = new Question(1, "size of int", "2", "6", "4", "8", "4");
questions[1] = new Question(2, "size of double", "2", "6", "4", "8", "8");
questions[2] = new Question(3, "size of char", "2", "6", "4", "8", "2");
questions[3] = new Question(4, "size of long", "2", "6", "4", "8", "8");
questions[4] = new Question(5, "size of boolean", "1", "2", "4", "8", "1");
}
public void playQuiz(){
int i=0;
for(Question q : questions){
System.out.println("Question No : " +q.getId());
System.out.println(q.getQuestion());
System.out.println(q.getOpt1());
System.out.println(q.getOpt2());
System.out.println(q.getOpt3());
System.out.println(q.getOpt4());
Scanner sc = new Scanner(System.in);
user[i]=sc.nextLine();
i++;
}
}
public void score () {
int score =0;
for(int i=0;i<user.length;i++){
String actans = questions[i].getAns();
String userans =user[i];
if(actans.equals(userans)){
score++;
}
}
System.out.println(score);
}
}