-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuestion.java
113 lines (98 loc) · 2.97 KB
/
Question.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
/**
* This is going to create the questions for the quiz
* @author word.exe
*/
import java.util.ArrayList;
public class Question {
private String questionTitle;
private ArrayList<String> answerChoices;
private int correctAnswer;
/**
* This is going to set up a question
* @param title this is going to be the name of the question
*/
public Question(String title) {
questionTitle = title;
this.answerChoices = new ArrayList<String>();
}
/**
* This is going to get a question
* @return the question title is returned with a new line
*/
public String getQuestion() {
return questionTitle + "\n";
}
/**
* This is going to remove certain answers from the questions
* @param index this is going to set up answers at a certain index
*/
public void removeAnswer(int index) {
answerChoices.remove(index);
}
/**
* This is going to add an answer to a question
* @param answer The answer that is added to the question as an option
*/
public void addAnswer(String answer) {
answerChoices.add(answer);
}
/**
* This is going to assign the answer to a certain location
* @param index this is going to be the location in the index where the answer is saved
* @param answer the answer that is added to the question as an option
*/
public void addAnswer(int index, String answer) {
answerChoices.add(index, answer);
}
/**
* This will print the answer choices to each quiz question
*/
public void printChoices() {
int number = 1;
for(String x: answerChoices) {
System.out.println(number + "." + x + "\n");
number++;
}
}
/**
* This is going to print the correct answer based on the question
*/
public void printCorrectAnswer() {
answerChoices.get(correctAnswer);
}
/**
* This is going to get the question title
* @return the question title
*/
public String getQuestionTitle() {
return this.questionTitle;
}
/**
* This is going to set the question title
* @param questionTitle the question title that was named
*/
public void setQuestionTitle(String questionTitle) {
this.questionTitle = questionTitle;
}
/**
* This is going to get the answer choices for the questions
* @return This is going to return the answer choices
*/
public ArrayList<String> getAnswerChoices() {
return this.answerChoices;
}
/**
* This is going to get the correct answer for the question
* @return the correct answer is returned
*/
public int getCorrectAnswer() {
return this.correctAnswer;
}
/**
* This is going to set the correct answer
* @param correctAnswer the correct answer for the quiz
*/
public void setCorrectAnswer(int correctAnswer) {
this.correctAnswer = correctAnswer;
}
}