From a073a21b28caba892e38d277d28ca022bbb1c232 Mon Sep 17 00:00:00 2001 From: maj83 Date: Tue, 28 Apr 2020 17:38:16 +0100 Subject: [PATCH 1/4] Refactored MatchTheMeaningQuestion to MatchTheMeaningController --- .../MatchTheMeaningQuestion.java | 204 +++++++++--------- 1 file changed, 104 insertions(+), 100 deletions(-) diff --git a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/selfassessment/MatchTheMeaningQuestion.java b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/selfassessment/MatchTheMeaningQuestion.java index 9fe712b..1f9fa2d 100644 --- a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/selfassessment/MatchTheMeaningQuestion.java +++ b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/selfassessment/MatchTheMeaningQuestion.java @@ -10,7 +10,6 @@ import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.control.ComboBox; import javafx.scene.control.Label; -import uk.ac.aber.cs22120.group20.javafx.Application; import uk.ac.aber.cs22120.group20.json.DictionaryEntry; import java.net.URL; import java.util.*; @@ -26,145 +25,150 @@ import java.util.*; * @author Oscar Pocock [osp1] * @author Tom Perry [top1] * @author Waylen Watts [ncw] - * @version 0.1 Initial development + * @version 0.4 Initial development * @see uk.ac.aber.cs22120.group20.javafx.Application */ -public class MatchTheMeaningQuestion extends Question implements Initializable{ +public class MatchTheMeaningController extends Question implements Initializable{ - public static ArrayList setOfQuestions=new ArrayList<>(); - private ArrayList orderList = new ArrayList<>(Arrays.asList(0,1,2,3)); - private boolean isEnglish; + private ArrayList setOfQuestions=new ArrayList<>(); + private ArrayList orderList = new ArrayList<>(Arrays.asList(0,1,2,3)); + private boolean isEnglish; - @FXML - private ComboBox word1; + @FXML + private ComboBox word1; - @FXML - private ComboBox word2; + @FXML + private ComboBox word2; - @FXML - private ComboBox word3; + @FXML + private ComboBox word3; - @FXML - private ComboBox word4; + @FXML + private ComboBox word4; - @FXML - private Label LeftWord1; + @FXML + private Label LeftWord1; - @FXML - private Label LeftWord2; + @FXML + private Label LeftWord2; - @FXML - private Label LeftWord3; + @FXML + private Label LeftWord3; - @FXML - private Label LeftWord4; + @FXML + private Label LeftWord4; - @FXML - private Label RightWord1; + @FXML + private Label RightWord1; - @FXML - private Label RightWord2; + @FXML + private Label RightWord2; - @FXML - private Label RightWord3; + @FXML + private Label RightWord3; - @FXML - private Label RightWord4; + @FXML + private Label RightWord4; - @FXML - private Label CorrectAnswer; + @FXML + private Label CorrectAnswer; - @FXML - private Label WrongAnswer; + @FXML + private Label WrongAnswer; - /** - * Pick randomly dictionary entry and add it to question list where are stored questions for this test. - */ - private void getQuestions(){ - AssessmentGenerator.generateSixMeanings(Application.dictionary); - } + /** + * Pick randomly dictionary entry and add it to question list where are stored questions for this test. + */ + private void getQuestions(){ - /** - * Set chosen words from dictionary on the scene. - * - * @param questions list of dictionary entries chosen for this test. - * @param orderList list of integers to change way of displaying welsh words. - */ + setOfQuestions.addAll(AssessmentGenerator.generateWordMatch()); + + } + + /** + * Set chosen words from dictionary on the scene. + * + * @param questions list of dictionary entries chosen for this test. + * @param orderList list of integers to change way of displaying welsh words. + */ - private void setWords(ArrayList questions, ArrayList orderList){ + private void setWords(ArrayList questions, ArrayList orderList){ - if(isEnglish){ - LeftWord1.setText(questions.get(0).getEnglish()); - LeftWord2.setText(questions.get(1).getEnglish()); - LeftWord3.setText(questions.get(2).getEnglish()); - LeftWord4.setText(questions.get(3).getEnglish()); + if(isEnglish){ + LeftWord1.setText(questions.get(0).getEnglish()); + LeftWord2.setText(questions.get(1).getEnglish()); + LeftWord3.setText(questions.get(2).getEnglish()); + LeftWord4.setText(questions.get(3).getEnglish()); - Collections.shuffle(orderList); + Collections.shuffle(orderList); - RightWord1.setText(questions.get(orderList.get(0)).getWelsh()); - RightWord1.setText(questions.get(orderList.get(1)).getWelsh()); - RightWord1.setText(questions.get(orderList.get(2)).getWelsh()); - RightWord1.setText(questions.get(orderList.get(3)).getWelsh()); + RightWord1.setText(questions.get(orderList.get(0)).getWelsh()); + RightWord1.setText(questions.get(orderList.get(1)).getWelsh()); + RightWord1.setText(questions.get(orderList.get(2)).getWelsh()); + RightWord1.setText(questions.get(orderList.get(3)).getWelsh()); - }else { - LeftWord1.setText(questions.get(0).getWelsh()); - LeftWord2.setText(questions.get(1).getWelsh()); - LeftWord3.setText(questions.get(2).getWelsh()); - LeftWord4.setText(questions.get(3).getWelsh()); + }else { + LeftWord1.setText(questions.get(0).getWelsh()); + LeftWord2.setText(questions.get(1).getWelsh()); + LeftWord3.setText(questions.get(2).getWelsh()); + LeftWord4.setText(questions.get(3).getWelsh()); - Collections.shuffle(orderList); + Collections.shuffle(orderList); - RightWord1.setText(questions.get(orderList.get(0)).getEnglish()); - RightWord1.setText(questions.get(orderList.get(1)).getEnglish()); - RightWord1.setText(questions.get(orderList.get(2)).getEnglish()); - RightWord1.setText(questions.get(orderList.get(3)).getEnglish()); - } + RightWord1.setText(questions.get(orderList.get(0)).getEnglish()); + RightWord1.setText(questions.get(orderList.get(1)).getEnglish()); + RightWord1.setText(questions.get(orderList.get(2)).getEnglish()); + RightWord1.setText(questions.get(orderList.get(3)).getEnglish()); + } - } + } - /** - * Check if answers from users are correct. - */ + /** + * Check if answers from users are correct. + */ - public void checkAnswers(){ - ArrayList listOfAnswers = new ArrayList<>(); - if(isEnglish){ - listOfAnswers.add(RightWord1.getText()); - listOfAnswers.add(RightWord2.getText()); - listOfAnswers.add(RightWord3.getText()); - listOfAnswers.add(RightWord4.getText()); - }else { - listOfAnswers.add(LeftWord1.getText()); - listOfAnswers.add(LeftWord2.getText()); - listOfAnswers.add(LeftWord3.getText()); - listOfAnswers.add(LeftWord4.getText()); - } + public void checkAnswers(){ + ArrayList listOfAnswers = new ArrayList<>(); + if(isEnglish){ + listOfAnswers.add(RightWord1.getText()); + listOfAnswers.add(RightWord2.getText()); + listOfAnswers.add(RightWord3.getText()); + listOfAnswers.add(RightWord4.getText()); + }else { + listOfAnswers.add(LeftWord1.getText()); + listOfAnswers.add(LeftWord2.getText()); + listOfAnswers.add(LeftWord3.getText()); + listOfAnswers.add(LeftWord4.getText()); + } - checkAnswer(setOfQuestions,listOfAnswers,isEnglish); + checkAnswer(setOfQuestions,listOfAnswers,isEnglish); - setOfQuestions.clear(); - this.prepare(); + CorrectAnswer.setText(Integer.toString(correctAnswers)); + WrongAnswer.setText(Integer.toString(wrongAnswers)); - } + setOfQuestions.clear(); + this.prepare(); - /** - * Method responsible for preparing questions and scene. - */ - private void prepare(){ - getQuestions(); - setWords(setOfQuestions,orderList); - } + } - @Override - public void initialize(URL url, ResourceBundle resourceBundle) { + /** + * Method responsible for preparing questions and scene. + */ + private void prepare(){ + getQuestions(); + setWords(setOfQuestions,orderList); + } - this.prepare(); + @Override + public void initialize(URL url, ResourceBundle resourceBundle) { - } + this.prepare(); + + } } From 8f16314814c8961f402e333376963018f59cec2f Mon Sep 17 00:00:00 2001 From: maj83 Date: Tue, 28 Apr 2020 17:40:40 +0100 Subject: [PATCH 2/4] Changes to fx:id controller --- .../resources/uk/ac/aber/cs22120/group20/matchthemeaning.fxml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Welsh Vocabulary Tutor/src/main/resources/uk/ac/aber/cs22120/group20/matchthemeaning.fxml b/src/Welsh Vocabulary Tutor/src/main/resources/uk/ac/aber/cs22120/group20/matchthemeaning.fxml index c98a9de..06407f2 100644 --- a/src/Welsh Vocabulary Tutor/src/main/resources/uk/ac/aber/cs22120/group20/matchthemeaning.fxml +++ b/src/Welsh Vocabulary Tutor/src/main/resources/uk/ac/aber/cs22120/group20/matchthemeaning.fxml @@ -7,7 +7,7 @@ - +