-
Notifications
You must be signed in to change notification settings - Fork 0
/
Quiz.java
88 lines (78 loc) · 2.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
/**
* This is going to set up quizzes
* @author word.exe
*/
import java.util.ArrayList;
import java.util.Scanner;
public class Quiz {
Scanner input = new Scanner(System.in);
private ArrayList<Question> questions;
private int answersCorrect = 0;
/**
* This is going to create an array list of the questions
*/
public Quiz() {
this.questions = new ArrayList<Question>();
}
/**
* This is going to set up the array list of questions in each quiz
* @param listOfQuestions the list of questions made
*/
public Quiz(ArrayList<Question> questions) {
this.questions = questions;
}
/**
* This is going to allow the user to take a quiz
*/
public void takeQuiz() {
int userAnswer;
for(Question x: questions) {
System.out.println(x.getQuestion());
x.printChoices();
Scanner scan = new Scanner(System.in);
userAnswer = scan.nextInt();
if(userAnswer == x.getCorrectAnswer()) {
System.out.println("correct");
answersCorrect++;
} else {
System.out.println("Incorrect");
}
}
}
/**
* This is going to allow for a question to be added
* @param question the question being added in
*/
public void addQuestion(Question question) {
questions.add(question);
}
/**
* This is going to add the question in to a position in the index
* @param index the location of the question
*/
public void addQuestion(Question question, int index) {
questions.add(index, question);
}
/**
* This is going to remove questions from the index
* @param index the location of the question
*/
public void removeQuestion(int index) {
questions.remove(index);
}
/**
* This is going to display if the user passed the quiz
* @return the score higher or equal to .8 and will return true if passed and false if not passed
*/
private boolean quizPassedCheck() {
double score = answersCorrect/questions.size();
return (score >= 0.8);
}
/**
* This is going to pull the questions
* @return the question is returned
*/
public ArrayList<Question> getQuestions() {
return this.questions;
}
}