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.
73 lines
1.9 KiB
73 lines
1.9 KiB
package com.mathlearning.model;
|
|
|
|
import java.io.Serializable;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class Paper implements Serializable {
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
private List<Question> questions;
|
|
private int currentQuestionIndex;
|
|
private String level;
|
|
|
|
public Paper(String level) {
|
|
this.questions = new ArrayList<>();
|
|
this.currentQuestionIndex = 0;
|
|
this.level = level;
|
|
}
|
|
|
|
public void addQuestion(Question question) {
|
|
questions.add(question);
|
|
}
|
|
|
|
public Question getCurrentQuestion() {
|
|
if (currentQuestionIndex < questions.size()) {
|
|
return questions.get(currentQuestionIndex);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public boolean hasNextQuestion() {
|
|
return currentQuestionIndex < questions.size() - 1;
|
|
}
|
|
|
|
public void nextQuestion() {
|
|
if (hasNextQuestion()) {
|
|
currentQuestionIndex++;
|
|
}
|
|
}
|
|
|
|
public boolean hasPreviousQuestion() {
|
|
return currentQuestionIndex > 0;
|
|
}
|
|
|
|
public void previousQuestion() {
|
|
if (hasPreviousQuestion()) {
|
|
currentQuestionIndex--;
|
|
}
|
|
}
|
|
|
|
public int getTotalQuestions() {
|
|
return questions.size();
|
|
}
|
|
|
|
public int getCurrentQuestionNumber() {
|
|
return currentQuestionIndex + 1;
|
|
}
|
|
|
|
public int calculateScore() {
|
|
int correctCount = 0;
|
|
for (Question q : questions) {
|
|
if (q.isCorrect()) {
|
|
correctCount++;
|
|
}
|
|
}
|
|
return (int) ((correctCount * 100.0) / questions.size());
|
|
}
|
|
|
|
public String getLevel() { return level; }
|
|
public void setLevel(String level) { this.level = level; }
|
|
|
|
public List<Question> getQuestions() { return questions; }
|
|
} |