-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion.java
More file actions
102 lines (89 loc) · 2.82 KB
/
Copy pathQuestion.java
File metadata and controls
102 lines (89 loc) · 2.82 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/** Question class-----
* Assigns point values and
* holds fields to verify correct answers.
*
* CS1800 Spring 2022, Project 4
* @author Taylor Graham, Alex Lee
* @version 4/5/2022
*/
public class Question {
private int pointValue;
private String prompt;
private String answer;
private String questionType; // Question type: M for multiple choice, R for response or True/False
/** Getter & Setter, Fields, Constructors
* CS1800 Spring 2022, Project 4
* @author Taylor Graham, Alex Lee
* @version 4/5/2022
*/
public Question(int pointValue, String prompt, String answer, String questionType) {
this.pointValue = pointValue;
this.prompt = prompt;
this.answer = answer;
this.questionType = questionType;
}
public Question(String prompt, String answer, String questionType) {
this.pointValue = 0;
this.prompt = prompt;
this.answer = answer;
this.questionType = questionType;
}
public String getPrompt() {
String prompt = "";
if (this.questionType.equals("R")) {
prompt = this.prompt;
} else if (this.questionType.equals("M")){
String[] promptElements = this.prompt.split(":");
prompt = promptElements[0];
} else if (this.questionType.equals("TF")) {
prompt = this.prompt + " (T/F)";
}
return prompt;
}
public String[] getMultipleOptions() {
String[] promptElements = this.prompt.split(":");
String[] multipleOptions = new String[promptElements.length - 1];
for (int i = 1 ; i < promptElements.length ; i++) {
multipleOptions[i - 1] = promptElements[i];
}
return multipleOptions;
}
public String getAnswer() {
return this.answer;
}
public int getPointValue() {
return this.pointValue;
}
public String getType() {
return this.questionType;
}
public void setPrompt( String prompt ) {
this.prompt = prompt;
}
public void setAnswer( String answer ) {
this.answer = answer;
}
public void setPointValue(int pointValue) {
this.pointValue = pointValue;
}
/** Grade each question, returning the full point value if correct, 0 if not
* CS1800 Spring 2022, Project 4
* @author Alex Lee
* @version 4/9/2022
*/
public int gradeQuestion( String response ) {
int pointsEarned = 0;
if (response.equalsIgnoreCase(getAnswer())) {
pointsEarned = getPointValue();
}
return pointsEarned;
}
/** toString method
* CS1800 Spring 2022, Project 4
* @author Alex Lee
* @version 4/9/2022
*/
public String toString(){
return String.format("%s,%s,%s/", this.prompt, this.answer, this.questionType);
}
}