From f537f3a25bf0daf6ea06386301b25f27c6a2a453 Mon Sep 17 00:00:00 2001 From: maj83 Date: Tue, 21 Apr 2020 12:49:45 +0100 Subject: [PATCH] Added loading from dictionary. --- .../Match the meaning/src/MyController.java | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/dev/20200414/maj83/Welsh Vocabulary Tutor/Match the meaning/src/MyController.java b/dev/20200414/maj83/Welsh Vocabulary Tutor/Match the meaning/src/MyController.java index ab57ba5..2e52465 100644 --- a/dev/20200414/maj83/Welsh Vocabulary Tutor/Match the meaning/src/MyController.java +++ b/dev/20200414/maj83/Welsh Vocabulary Tutor/Match the meaning/src/MyController.java @@ -1,6 +1,5 @@ import javafx.fxml.FXML; import javafx.fxml.Initializable; -import javafx.scene.control.Button; import javafx.scene.control.ComboBox; import javafx.scene.control.Label; @@ -12,8 +11,9 @@ public class MyController implements Initializable { private Random rand = new Random(); public LinkedList setOfQuestions=new LinkedList<>(); private ArrayList temp1 = new ArrayList<>(Arrays.asList(0,1,2,3)); - int corAns = 0; - int wrongAns = 0; + private int corAns = 0; + private int wrongAns = 0; + private boolean isDuplicate = false; @FXML private ComboBox word1; @@ -77,28 +77,24 @@ public class MyController implements Initializable { do{ int rand_q=rand.nextInt(dictionary.size()-1); DictionaryEntry pickedQuestion = dictionary.get(rand_q); - if(setOfQuestions.size()>1){ - for(int i=0;i=1){ + for (DictionaryEntry setOfQuestion : setOfQuestions) { + if (setOfQuestion.equals(pickedQuestion)) { + isDuplicate = true; break; - }else { - setOfQuestions.add(pickedQuestion); } } + if(!isDuplicate){ + setOfQuestions.add(pickedQuestion); + } }else{ setOfQuestions.add(pickedQuestion); } - + isDuplicate =false; }while(setOfQuestions.size()<5); return setOfQuestions; } - private void fill(){ - setOfQuestions.add(new DictionaryEntry("abbey", "abaty", "nm")); - setOfQuestions.add(new DictionaryEntry("believe", "credu", "verb")); - setOfQuestions.add(new DictionaryEntry("concert", "cyngerdd", "nm")); - setOfQuestions.add(new DictionaryEntry("disease", "clefyd", "nm")); - } public void checkAnswers(){ int w1 = Integer.parseInt(word1.getValue())-1; @@ -129,7 +125,7 @@ public class MyController implements Initializable { @Override public void initialize(URL url, ResourceBundle resourceBundle) { - this.fill(); + getQuestions(Main.dictionary); TestLabel(setOfQuestions,temp1); } }