|
|
|
|
@ -6,10 +6,14 @@ import java.util.*;
|
|
|
|
|
public class QuestionService {
|
|
|
|
|
/*生成试卷的题目部分*/
|
|
|
|
|
public List<Question> generateQuestions(String difficulty, int count) {
|
|
|
|
|
if(count < 10 || count > 30) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Question> questions = new ArrayList<>();
|
|
|
|
|
Set<String> usedQuestions = new HashSet<>();
|
|
|
|
|
QuestionGenerator generator = QuestionGeneratorFactory.getGenerator(difficulty);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (questions.size() < count) {
|
|
|
|
|
Question q = generator.generateQuestion();
|
|
|
|
|
if (usedQuestions.add(q.getContent())) {
|
|
|
|
|
|