package xmh.com;
public class QuizBean {
private int currentProblem;
private int score;
private String response;
private String correctAnswer;
QuestionBiz qbiz = new QuestionBiz();
private Problem[] problems = qbiz.getProblems();
public QuizBean() {
startOver();
}
public String getQuestion() {
return problems[currentProblem].getQuestion();
}
public String getAnswer() {
return correctAnswer;
}
public String getCorrectAnswer() {
return correctAnswer;
}
public void setCorrectAnswer(String correctAnswer) {
this.correctAnswer = correctAnswer;
}
public int getCurrentProblem() {
return currentProblem;
}
public void setCurrentProblem(int currentProblem) {
this.currentProblem = currentProblem;
}
public String getResponse() {
return response;
}
public void setResponse(String response) {
this.response = response;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public String answerAction() {
if (qbiz.isCorrect(response,problems[currentProblem])) {
score++;
nextProblem();
if (currentProblem == problems.length) {
return "done";
} else {
return "success";
}
} else {
nextProblem();
if (currentProblem == problems.length) {
return "done";
} else {
return "failure";
}
}
}
public String startOverAction() {
startOver();
return "startOver";
}
private void startOver() {
currentProblem = 0;
score = 0;
response = "";
}
private void nextProblem() {
correctAnswer = problems[currentProblem].getAnswer();
currentProblem++;
response = "";
}
}