-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathQuestionList.java
More file actions
76 lines (64 loc) · 2.11 KB
/
QuestionList.java
File metadata and controls
76 lines (64 loc) · 2.11 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
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeSet;
public class QuestionList {
private ArrayList<Question> questions;
private boolean hasQuestions;
public QuestionList() {
this.questions = new ArrayList<>();
this.hasQuestions = false;
}
public void addQuestion(Question question) {
questions.add(question);
hasQuestions = true;
}
public void display() {
if (questions.isEmpty()) {
System.out.println("No questions available.");
return;
}
// Group questions by category
Map<String, TreeSet<Integer>> categoryMap = new HashMap<>();
for (Question q : questions) {
categoryMap.putIfAbsent(q.getCategory(), new TreeSet<>());
categoryMap.get(q.getCategory()).add(q.getValue());
}
// Display header
System.out.println("\n" + "=".repeat(60));
System.out.println("QUESTION BOARD");
System.out.println("=".repeat(60));
// Display categories and values
for (Map.Entry<String, TreeSet<Integer>> entry : categoryMap.entrySet()) {
System.out.println("\n" + entry.getKey() + ":");
System.out.print(" Values: ");
for (Integer value : entry.getValue()) {
System.out.print(value + " ");
}
System.out.println();
}
System.out.println("=".repeat(60) + "\n");
}
public Question searchQuestion(String category, int value) {
for (Question q : questions) {
if (q.getCategory().equalsIgnoreCase(category) && q.getValue() == value) {
return q;
}
}
return null;
}
public boolean checkHasQuestions() {
hasQuestions = false;
for (Question q : questions) {
if (q.getValue() > 0 && !q.isAnswered()) {
hasQuestions = true;
break;
}
}
return hasQuestions;
}
public ArrayList<Question> getQuestions() {
return questions;
}
}