-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathQuestion.java
More file actions
80 lines (69 loc) · 2.09 KB
/
Question.java
File metadata and controls
80 lines (69 loc) · 2.09 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import java.util.ArrayList;
import java.util.List;
public class Question {
private String category;
private int value;
private String content;
private ArrayList<String> options;
private String correctAnswer;
private ArrayList<String> answers;
private boolean isAnswered;
//Accessors and Mutators
public String getCategory() {
return category;
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
public String getContent() {
return content;
}
public ArrayList<String> getOptions() {
return options;
}
public String getRightAnswer() {
return correctAnswer;
}
public ArrayList<String> getAnswers() {
return answers;
}
public boolean isAnswered() {
return isAnswered;
}
public void setAnswered(boolean answered) {
isAnswered = answered;
}
public void addOption(String option) {
options.add(option);
}
public Question(String category, int value, String content, List<String> options, String rightAnswer) {
this.category = category;
this.value = value;
this.content = content;
this.options = new ArrayList<>();
this.correctAnswer = rightAnswer;
this.answers = new ArrayList<>();
this.isAnswered = false;
}
//Display question details
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("Category: ").append(category).append("\n");
sb.append("Value: ").append(value).append("\n");
sb.append("Question: ").append(content).append("\n");
if(options != null && !options.isEmpty())
sb.append("Options: \n");
for(int i = 0; i < options.size(); i++ ) {
sb.append((i + 1)).append(". ").append(options.get(i)).append("\n");
}
return sb.toString();
}
public void addAnswer(String answer) {
if (!answers.contains(answer)) {
answers.add(answer);
}
}
}