-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankQuestionSource.java
More file actions
36 lines (31 loc) · 1.14 KB
/
Copy pathBankQuestionSource.java
File metadata and controls
36 lines (31 loc) · 1.14 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
import java.util.List;
import java.util.Random;
/**
* PART D: Question Sourcing Integration
* Concrete QuestionSource - fetches pseudo-random predefined questions
* from the QuestionBank repository.
*/
public class BankQuestionSource implements QuestionSource {
private final Random random = new Random();
private final List<Question> bank;
private final String questionType;
/**
* @param questionType Filters bank items by type (e.g. "MCQ", "Essay").
* Pass null to draw from the full bank.
*/
public BankQuestionSource(String questionType) {
this.questionType = questionType;
this.bank = QuestionBank.getAll();
}
@Override
public Question getQuestion() {
List<Question> filtered = bank.stream()
.filter(q -> questionType == null || q.getType().equalsIgnoreCase(questionType))
.toList();
if (filtered.isEmpty()) {
throw new IllegalStateException(
"No questions of type '" + questionType + "' found in the bank.");
}
return filtered.get(random.nextInt(filtered.size()));
}
}