You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
657 B
25 lines
657 B
package service;
|
|
|
|
import model.Question;
|
|
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())) {
|
|
questions.add(q);
|
|
}
|
|
}
|
|
return questions;
|
|
}
|
|
} |