From 67d511f111e1b3ca1645f1215465ffdd5d1c7ad7 Mon Sep 17 00:00:00 2001 From: law39 Date: Fri, 1 May 2020 11:08:16 +0100 Subject: [PATCH] Updated Assessment Controllers and FXML. Correct issue #31 Correct And Total answers are now displayed, the number and text are now displayed in the same text label to reduce issues with Screen Scaling --- .../javafx/MatchTheMeaningController.java | 60 ++++++++++--------- .../group20/javafx/SixMeaningsController.java | 38 ++++++------ .../group20/javafx/TranslationController.java | 30 +++++----- .../aber/cs221/group20/matchthemeaning.fxml | 30 ++++------ .../uk/ac/aber/cs221/group20/sixmeanings.fxml | 18 ++---- .../uk/ac/aber/cs221/group20/translation.fxml | 13 ++-- 6 files changed, 87 insertions(+), 102 deletions(-) diff --git a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/MatchTheMeaningController.java b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/MatchTheMeaningController.java index 36ae0f5..fdcc780 100644 --- a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/MatchTheMeaningController.java +++ b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/MatchTheMeaningController.java @@ -40,14 +40,14 @@ public class MatchTheMeaningController extends SharedCodeController { // Class variables. // // //////////////// // - public static ArrayList answer =new ArrayList<>(); + public static ArrayList answer = new ArrayList<>(); // /////////////////// // // Instance variables. // // /////////////////// // - private ArrayList orderList = new ArrayList<>(Arrays.asList(0,1,2,3)); - private boolean isEnglish = AssessmentGenerator.isEnglish; + private final ArrayList orderList = new ArrayList<>(Arrays.asList(0, 1, 2, 3)); + private final boolean isEnglish = AssessmentGenerator.isEnglish; @FXML private ComboBox word1; @@ -86,10 +86,10 @@ public class MatchTheMeaningController extends SharedCodeController { private Label RightWord4; @FXML - private Label CorrectAnswer; + private Label correctAnswer; @FXML - private Label WrongAnswer; + private Label totalAnswer; // //////// // // Methods. // @@ -103,10 +103,10 @@ public class MatchTheMeaningController extends SharedCodeController { */ - public void setWords(ArrayList questions, ArrayList orderList){ + public void setWords(ArrayList questions, ArrayList orderList) { - if(isEnglish){ + if (isEnglish) { LeftWord1.setText(questions.get(0).getEnglish()); LeftWord2.setText(questions.get(1).getEnglish()); LeftWord3.setText(questions.get(2).getEnglish()); @@ -119,7 +119,7 @@ public class MatchTheMeaningController extends SharedCodeController { RightWord3.setText(questions.get(orderList.get(2)).getWelsh()); RightWord4.setText(questions.get(orderList.get(3)).getWelsh()); - }else { + } else { LeftWord1.setText(questions.get(0).getWelsh()); LeftWord2.setText(questions.get(1).getWelsh()); LeftWord3.setText(questions.get(2).getWelsh()); @@ -139,23 +139,23 @@ public class MatchTheMeaningController extends SharedCodeController { * Check if answers from users are correct. */ - public void checkAnswers(){ + public void checkAnswers() { ArrayList answers = new ArrayList<>(); ArrayList listOfAnswers = new ArrayList<>(); - answers.add(answer.get(Integer.parseInt(word1.getValue())-1)); - answers.add(answer.get(Integer.parseInt(word2.getValue())-1)); - answers.add(answer.get(Integer.parseInt(word3.getValue())-1)); - answers.add(answer.get(Integer.parseInt(word4.getValue())-1)); + answers.add(answer.get(Integer.parseInt(word1.getValue()) - 1)); + answers.add(answer.get(Integer.parseInt(word2.getValue()) - 1)); + answers.add(answer.get(Integer.parseInt(word3.getValue()) - 1)); + answers.add(answer.get(Integer.parseInt(word4.getValue()) - 1)); - if(isEnglish){ + if (isEnglish) { listOfAnswers.add(LeftWord1.getText()); listOfAnswers.add(LeftWord2.getText()); listOfAnswers.add(LeftWord3.getText()); listOfAnswers.add(LeftWord4.getText()); - }else { + } else { listOfAnswers.add(RightWord1.getText()); listOfAnswers.add(RightWord2.getText()); listOfAnswers.add(RightWord3.getText()); @@ -163,13 +163,13 @@ public class MatchTheMeaningController extends SharedCodeController { } - if(checkForDuplicates(answers)){ + 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 { + } else { Question.checkAnswer(answers, listOfAnswers, isEnglish); @@ -178,19 +178,19 @@ public class MatchTheMeaningController extends SharedCodeController { AssessmentGenerator.goToNextQuestion(); } } - private boolean checkForDuplicates(ArrayList wordSet){ - boolean result = false; - Set set = new HashSet<>(wordSet); - if(set.size() < wordSet.size()){ - result = true; - } - return result; + 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")); @@ -199,9 +199,11 @@ public class MatchTheMeaningController extends SharedCodeController { studyIcon.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/pass-fail-50.png")); studyText.setFill(Color.BLACK); - setWords(answer,orderList); - CorrectAnswer.setText(Integer.toString(AssessmentGenerator.getTotalCorrectAnswers())); - WrongAnswer.setText(Integer.toString(AssessmentGenerator.getTotalAnswers())); + setWords(answer, orderList); + correctAnswer.setText("Correct answers : " + AssessmentGenerator.getTotalCorrectAnswers()); + + totalAnswer.setText("Total answers : " + AssessmentGenerator.getTotalAnswers()); + } } diff --git a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/SixMeaningsController.java b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/SixMeaningsController.java index d88e238..e651a52 100644 --- a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/SixMeaningsController.java +++ b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/SixMeaningsController.java @@ -16,7 +16,9 @@ import uk.ac.aber.cs221.group20.json.DictionaryEntry; import uk.ac.aber.cs221.group20.selfassessment.AssessmentGenerator; import uk.ac.aber.cs221.group20.selfassessment.Question; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; /** * A class that generate questions and check answers for match the meaning test. @@ -45,16 +47,16 @@ public class SixMeaningsController extends SharedCodeController { // Instance variables. // // /////////////////// // - private ArrayList wordSet = new ArrayList<>(); - private ArrayList orderList = new ArrayList<>(Arrays.asList(0, 1, 2, 3, 4, 5)); + private final ArrayList wordSet = new ArrayList<>(); + private final ArrayList orderList = new ArrayList<>(Arrays.asList(0, 1, 2, 3, 4, 5)); private String wordCounterpart; - private boolean isEnglish = AssessmentGenerator.isEnglish; + private final boolean isEnglish = AssessmentGenerator.isEnglish; @FXML - private Text correctAnswer; + private Label correctAnswer; @FXML - private Text wrongAnswer; + private Label totalAnswer; @FXML private Label wordToTranslate; @@ -86,26 +88,31 @@ public class SixMeaningsController extends SharedCodeController { wordCounterpart = possibleAnswer1.getText(); checkAnswers(); } + @FXML void answer2(MouseEvent event) { wordCounterpart = possibleAnswer2.getText(); checkAnswers(); } + @FXML void answer3(MouseEvent event) { wordCounterpart = possibleAnswer3.getText(); checkAnswers(); } + @FXML void answer4(MouseEvent event) { wordCounterpart = possibleAnswer4.getText(); checkAnswers(); } + @FXML void answer5(MouseEvent event) { wordCounterpart = possibleAnswer5.getText(); checkAnswers(); } + @FXML void answer6(MouseEvent event) { wordCounterpart = possibleAnswer6.getText(); @@ -113,10 +120,9 @@ public class SixMeaningsController extends SharedCodeController { } + public void setWords(ArrayList questions, ArrayList orderList) { - public void setWords(ArrayList questions, ArrayList orderList){ - - if(isEnglish){ + if (isEnglish) { wordSet.add(questions.get(0)); @@ -132,7 +138,7 @@ public class SixMeaningsController extends SharedCodeController { possibleAnswer4.setText(questions.get(orderList.get(3)).getWelsh()); possibleAnswer5.setText(questions.get(orderList.get(4)).getWelsh()); possibleAnswer6.setText(questions.get(orderList.get(5)).getWelsh()); - }else { + } else { wordSet.add(questions.get(0)); //WelshWord1 Is the question word and as a result is always right. @@ -153,15 +159,13 @@ public class SixMeaningsController extends SharedCodeController { } - public void checkAnswers() { ArrayList answer = new ArrayList<>(); answer.add(wordCounterpart); - Question.checkAnswer(wordSet,answer,isEnglish); - + Question.checkAnswer(wordSet, answer, isEnglish); wordSet.clear(); @@ -180,11 +184,11 @@ public class SixMeaningsController extends SharedCodeController { studyIcon.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/pass-fail-50.png")); studyText.setFill(Color.BLACK); - setWords(allQuestions,orderList); - - correctAnswer.setText(Integer.toString(AssessmentGenerator.getTotalCorrectAnswers())); + setWords(allQuestions, orderList); - wrongAnswer.setText(Integer.toString(AssessmentGenerator.getTotalAnswers())); + correctAnswer.setText("Correct answers : " + AssessmentGenerator.getTotalCorrectAnswers()); + + totalAnswer.setText("Total answers : " + AssessmentGenerator.getTotalAnswers()); } diff --git a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/TranslationController.java b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/TranslationController.java index 136d7cc..a14017c 100644 --- a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/TranslationController.java +++ b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/TranslationController.java @@ -1,28 +1,27 @@ package uk.ac.aber.cs221.group20.javafx; import javafx.fxml.FXML; +import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.paint.Color; import javafx.scene.text.Text; - -import java.util.ArrayList; -import java.util.Random; - import uk.ac.aber.cs221.group20.json.DictionaryEntry; import uk.ac.aber.cs221.group20.selfassessment.AssessmentGenerator; import uk.ac.aber.cs221.group20.selfassessment.Question; +import java.util.ArrayList; +import java.util.Random; + /** * Controller for the translationTest fxml file. * * @author Brad Corbett brc9 * @version 0.1 - * */ -public class TranslationController extends SharedCodeController{ +public class TranslationController extends SharedCodeController { // //////////////// // // Class variables. // @@ -48,10 +47,10 @@ public class TranslationController extends SharedCodeController{ private Text wordToTranslate; @FXML - private Text correctGuesses; + private Label correctAnswer; @FXML - private Text incorrectGuesses; + private Label totalAnswer; @FXML private ImageView submitButton; @@ -68,7 +67,7 @@ public class TranslationController extends SharedCodeController{ * which is the first word the user will have to translate. */ @FXML - private void initialize(){ + private void initialize() { setup(); currentPageIcon.setImage(new Image("file:src/main/resources/assets/icons/white_icons/50px/pass-fail-50.png")); currentPageText.setText("Study"); @@ -76,17 +75,16 @@ public class TranslationController extends SharedCodeController{ studyIcon.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/pass-fail-50.png")); studyText.setFill(Color.BLACK); - submitButton.setImage(new Image ("file:src/main/resources/assets/icons/black_icons/50px/right-50.png")); + submitButton.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/right-50.png")); - correctGuesses.setText("Correct answers: " + AssessmentGenerator.getTotalCorrectAnswers()); - incorrectGuesses.setText("Total answers: " + AssessmentGenerator.getTotalAnswers()); + correctAnswer.setText("Correct answers : " + AssessmentGenerator.getTotalCorrectAnswers()); + + totalAnswer.setText("Total answers : " + AssessmentGenerator.getTotalAnswers()); - - if(AssessmentGenerator.isEnglish){ + if (AssessmentGenerator.isEnglish) { wordToTranslate.setText(answer.getEnglish()); - } - else{ + } else { wordToTranslate.setText(answer.getWelsh()); } } diff --git a/src/Welsh Vocabulary Tutor/src/main/resources/uk/ac/aber/cs221/group20/matchthemeaning.fxml b/src/Welsh Vocabulary Tutor/src/main/resources/uk/ac/aber/cs221/group20/matchthemeaning.fxml index 001204d..51812f7 100644 --- a/src/Welsh Vocabulary Tutor/src/main/resources/uk/ac/aber/cs221/group20/matchthemeaning.fxml +++ b/src/Welsh Vocabulary Tutor/src/main/resources/uk/ac/aber/cs221/group20/matchthemeaning.fxml @@ -128,30 +128,20 @@ - - + - - + diff --git a/src/Welsh Vocabulary Tutor/src/main/resources/uk/ac/aber/cs221/group20/sixmeanings.fxml b/src/Welsh Vocabulary Tutor/src/main/resources/uk/ac/aber/cs221/group20/sixmeanings.fxml index 25fc4ee..12c41db 100644 --- a/src/Welsh Vocabulary Tutor/src/main/resources/uk/ac/aber/cs221/group20/sixmeanings.fxml +++ b/src/Welsh Vocabulary Tutor/src/main/resources/uk/ac/aber/cs221/group20/sixmeanings.fxml @@ -150,24 +150,14 @@ - + - - + - diff --git a/src/Welsh Vocabulary Tutor/src/main/resources/uk/ac/aber/cs221/group20/translation.fxml b/src/Welsh Vocabulary Tutor/src/main/resources/uk/ac/aber/cs221/group20/translation.fxml index a3b4540..b8852c4 100644 --- a/src/Welsh Vocabulary Tutor/src/main/resources/uk/ac/aber/cs221/group20/translation.fxml +++ b/src/Welsh Vocabulary Tutor/src/main/resources/uk/ac/aber/cs221/group20/translation.fxml @@ -13,6 +13,7 @@ + - + - + + +