-
Notifications
You must be signed in to change notification settings - Fork 0
/
Question.java
66 lines (55 loc) · 1.72 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
import java.io.Serializable;
import java.util.ArrayList;
public class Question implements Serializable{
/**
*
*/
private static final long serialVersionUID = 8444550158617467279L;
String questionStatement = "Question";
ArrayList<String> choiceList = new ArrayList<String>();
int correctChoice = 0;
// Constructer the question with proposition
public Question(String text) {
questionStatement = text;
}
// Edit proposition
public void setQuestionStatement(String questionStatement) {
this.questionStatement = questionStatement;
}
// Get String of proposition
public String getQuestionStatement() {
return questionStatement;
}
// Add choice in the question
public void addChoice(String text) {
choiceList.add(text);
}
// Edit choice
public void setChoice(int i, String text) {
choiceList.set(i, text);
}
// Get String of each choice
public String getChoice(int number) {
return choiceList.get(number);
}
// Set the correct choice
public void setCorrectChoice(int number) {
correctChoice = number;
}
// Get the correct choice
public int getCorrectChoice() {
return correctChoice;
}
// How many choice
public int size() {
return choiceList.size();
}
public String toString() {
String text = questionStatement;
for (int i = 0 ; i < choiceList.size() ; i++) {
text += "\n" + (char)(i + 65) + ". " + choiceList.get(i).toString();
}
text += "\n" + "Correct answer is (" + (char)(correctChoice + 65) + ")";
return text;
}
}