implemt the testconroller without error handeling
This commit is contained in:
parent
7bb22fccd9
commit
3c5f9c7bbf
@ -49,6 +49,8 @@ public class TestController {
|
||||
private ObservableList<Question> questions;
|
||||
private ArrayList<String> answers = new ArrayList<>();
|
||||
private int currentIdx = 0;
|
||||
private int correctCount = 0;
|
||||
private int inCorrectCount = 0;
|
||||
|
||||
@FXML
|
||||
private void initialize() throws SQLException {
|
||||
@ -87,10 +89,14 @@ public class TestController {
|
||||
|
||||
@FXML
|
||||
private void onCorrectBtnClick(ActionEvent actionEvent) {
|
||||
correctCount++;
|
||||
displayNextQuestionCorrectionn();
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void onIncorrectBtnClick(ActionEvent actionEvent) {
|
||||
inCorrectCount ++;
|
||||
displayNextQuestionCorrectionn();
|
||||
}
|
||||
|
||||
public void onStartTestBtnClick(ActionEvent actionEvent) throws SQLException {
|
||||
@ -99,18 +105,46 @@ public class TestController {
|
||||
.GetQuestionsFromCatalog(((QuestionCatalog) catalogComboBox.getValue()).getId());
|
||||
this.questions = FXCollections.observableList(Utils.getRandom(questions, (int) this.questionSlider.getValue()));
|
||||
this.questionLabel.setText(this.questions.get(currentIdx).getQuestion());
|
||||
this.userAnswerArea.clear();
|
||||
}
|
||||
|
||||
public void showNextQuestion(ActionEvent actionEvent) {
|
||||
@FXML
|
||||
private void showNextQuestion(ActionEvent actionEvent) {
|
||||
this.answers.add(this.userAnswerArea.getText());
|
||||
currentIdx++;
|
||||
if(currentIdx >= this.questions.size())
|
||||
{
|
||||
this.isInCorrectionState.setValue(true);
|
||||
this.questionLabel.setText("Rate your Answers !");
|
||||
this.currentIdx = -1;
|
||||
displayNextQuestionCorrectionn();
|
||||
return;
|
||||
}
|
||||
this.userAnswerArea.clear();
|
||||
this.questionLabel.setText(this.questions.get(currentIdx).getQuestion());
|
||||
}
|
||||
|
||||
private void displayNextQuestionCorrectionn()
|
||||
{
|
||||
currentIdx ++;
|
||||
if(currentIdx == this.answers.size())
|
||||
{
|
||||
this.isInConfiguringState.setValue(true);
|
||||
this.isInCorrectionState.setValue(false);
|
||||
this.currentIdx = 0;
|
||||
displayResult();
|
||||
this.correctCount = 0;
|
||||
this.inCorrectCount = 0;
|
||||
this.answers.clear();
|
||||
return;
|
||||
}
|
||||
this.questionLabel.setText(this.questions.get(currentIdx).getQuestion());
|
||||
this.userAnswerArea.setText(this.answers.get(currentIdx));
|
||||
this.correctAnswerArea.setText(this.questions.get(currentIdx).getAnswer());
|
||||
}
|
||||
|
||||
private void displayResult()
|
||||
{
|
||||
this.userAnswerArea.setText("Correct: %d \nIncorrect: %d\n".formatted(correctCount, inCorrectCount));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user