-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion.java
More file actions
60 lines (51 loc) · 1.84 KB
/
Copy pathQuestion.java
File metadata and controls
60 lines (51 loc) · 1.84 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
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;
public class Question {
private int difficulty;
private String questionText;
private String defaultAnswer = "Answer";
public Question(int difficulty, String questionText) {
this.difficulty = difficulty;
this.questionText = questionText;
}
public static void reorderQuestions(List<Question> questions) {
Collections.sort(questions, Comparator.comparing(Question::getDifficulty));
}
public static String printWithAnswers(List<Question> questions) throws IOException {
StringJoiner joiner = new StringJoiner("\n\n");
for (int index = 0; index < questions.size(); index++) {
joiner.add(
String.format("%d) %s \n%s",
index + 1,
questions.get(index).questionText,
questions.get(index).getAnswer())
);
}
return joiner.toString();
}
public String getAnswer() {
return "Answer";
}
public static String print(List<Question> questions) {
StringJoiner joiner = new StringJoiner("\n\n");
for (int index = 0; index < questions.size(); index++) {
joiner.add(
String.format("%d) %s \n%s",
index + 1,
questions.get(index).questionText,
questions.get(index).getDefaultAnswer())
);
}
return joiner + "\n";
}
public int getDifficulty() {
return difficulty;
}
public String getDefaultAnswer() {
return defaultAnswer;
}
public void setDefaultAnswer(String defaultAnswer) {
this.defaultAnswer = defaultAnswer;
}
}