From 49a8d54bc5704aaf3bff3fa65a6e3f74c3ca834f Mon Sep 17 00:00:00 2001 From: law39 Date: Thu, 30 Apr 2020 14:35:31 +0100 Subject: [PATCH] Match the Meaning Controller Updated Match the Meaning Controller now contains an Alert which is displayed if the user attempts to submit answers to the question with duplicate answers --- .../javafx/MatchTheMeaningController.java | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/javafx/MatchTheMeaningController.java b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/javafx/MatchTheMeaningController.java index 23668f6..85b68c5 100644 --- a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/javafx/MatchTheMeaningController.java +++ b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/javafx/MatchTheMeaningController.java @@ -8,6 +8,7 @@ package uk.ac.aber.cs22120.group20.javafx; import javafx.fxml.FXML; import javafx.fxml.Initializable; +import javafx.scene.control.Alert; import javafx.scene.control.ComboBox; import javafx.scene.control.Label; import javafx.scene.image.Image; @@ -156,16 +157,34 @@ public class MatchTheMeaningController extends SharedCodeController { } - Question.checkAnswer(answers,listOfAnswers,isEnglish); + if(checkForDuplicates(answers)){ + Alert alert = new Alert(Alert.AlertType.ERROR); + alert.setTitle("Error"); + alert.setHeaderText("Please check answers"); + alert.setContentText("Please ensure you have selected answers for each test word, with no duplicates."); + alert.showAndWait(); + }else { + + Question.checkAnswer(answers, listOfAnswers, isEnglish); - answer.clear(); - AssessmentGenerator.goToNextQuestion(); - + answer.clear(); + AssessmentGenerator.goToNextQuestion(); + } } + private boolean checkForDuplicates(ArrayList wordSet){ + boolean result = false; + Set set = new HashSet<>(wordSet); + + if(set.size() < wordSet.size()){ + result = true; + } + return result; + } - @FXML + + @FXML private void initialize() { setup(); currentPageIcon.setImage(new Image("file:src/main/resources/assets/icons/white_icons/50px/pass-fail-50.png")); @@ -175,8 +194,8 @@ public class MatchTheMeaningController extends SharedCodeController { studyText.setFill(Color.BLACK); setWords(answer,orderList); - CorrectAnswer.setText(Integer.toString(Question.correctAnswers)); - WrongAnswer.setText(Integer.toString(Question.wrongAnswers)); + CorrectAnswer.setText(Integer.toString(AssessmentGenerator.getTotalCorrectAnswers())); + WrongAnswer.setText(Integer.toString(AssessmentGenerator.getTotalAnswers())); } }