我只需要比较givenanswers的答案和questions中每个问题的正确答案,然后返回失败问题列表。我想知道我怎么能对兰达斯做同样的事。
private List<Question> checkAnswer(List<Answer> givenAnswers, List<Question> questions){
List<Question> failedQuestions = new ArrayList<>();
for(int i=0; i<givenAnswers.size(); i++){
if(!givenAnswers.get(i).toString().equalsIgnoreCase(questions.get(i)
.getCorrectAnswer().toString()))
failedQuestions.add(questions.get(i));
}
return failedQuestions;
}
以下是答案类的代码:
public class Answer {
private final String content;
public Answer(String content) {
this.content = content;
}
@Override
public String toString() {
return content;
}
}
还有问题课:
public class Question {
private final int id;
private final String content;
private final List<Answer> answerList;
private final Answer correctAnswer;
public Question(int id, String content, List<Answer> answerList, Answer correctAnswer) {
this.id = id;
this.content = content;
this.answerList = answerList;
this.correctAnswer = correctAnswer;
}
public int getId() {
return id;
}
public String getContent() {
return content;
}
public List<Answer> getAnswerList() {
return answerList;
}
public Answer getCorrectAnswer(){
return correctAnswer;
}
@Override
public String toString() {
StringBuilder answersInLine = new StringBuilder();
for (Answer answer : answerList) {
answersInLine.append(answer.toString()).append('\t');
}
return "Question " + id +
":\n" + content +
'\n' + answersInLine.toString() + '\n';
}
}
有什么简单的解决办法吗?
1条答案
按热度按时间ct2axkht1#
两个数组,可能lambdas不适合。