From c2e93150e735f7c9d6c3b27d10a7babeb957c540 Mon Sep 17 00:00:00 2001 From: law39 Date: Thu, 30 Apr 2020 16:11:08 +0100 Subject: [PATCH] Updated Assessment Generator Assessment Generator has now been re-indented to have 3 spaces instead of 4 --- .../selfassessment/AssessmentGenerator.java | 334 +++++++++--------- 1 file changed, 167 insertions(+), 167 deletions(-) diff --git a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/selfassessment/AssessmentGenerator.java b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/selfassessment/AssessmentGenerator.java index 8b0d27c..a66bdf5 100644 --- a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/selfassessment/AssessmentGenerator.java +++ b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/selfassessment/AssessmentGenerator.java @@ -32,202 +32,202 @@ import java.util.*; * @see MatchTheMeaningController */ public class AssessmentGenerator { - public static boolean isEnglish; - static LinkedList listOfAssessment = new LinkedList<>(); - static int currentAssessment = 0; - static int totalCorrectAnswers = 0; - static int totalAnswers = 0; + public static boolean isEnglish; + static LinkedList listOfAssessment = new LinkedList<>(); + static int currentAssessment = 0; + static int totalCorrectAnswers = 0; + static int totalAnswers = 0; - /** - * Method that will generate a randomized list of questions consisting of random distribution of questions - * types, using the dictionary’s practice words as the parameter. - * - * @param practiseList - * @return - */ - public static LinkedList generateAssessment(LinkedList practiseList) { - LinkedList listOfAssessment = new LinkedList<>(); - Random rand = new Random(); + /** + * Method that will generate a randomized list of questions consisting of random distribution of questions + * types, using the dictionary’s practice words as the parameter. + * + * @param practiseList + * @return + */ + public static LinkedList generateAssessment(LinkedList practiseList) { + LinkedList listOfAssessment = new LinkedList<>(); + Random rand = new Random(); - reset(); + reset(); - //int wordToTranslatePlace; + //int wordToTranslatePlace; - if (practiseList.size()<5){ - Alert alert = new Alert(Alert.AlertType.ERROR); - alert.setTitle("Error"); - alert.setHeaderText("Not enough words in practice list"); - alert.setResizable(false); - alert.setContentText("Please add more words to your practice list on the dictionary page before trying to test yourself!"); - alert.showAndWait(); - }else { + if (practiseList.size()<5){ + Alert alert = new Alert(Alert.AlertType.ERROR); + alert.setTitle("Error"); + alert.setHeaderText("Not enough words in practice list"); + alert.setResizable(false); + alert.setContentText("Please add more words to your practice list on the dictionary page before trying to test yourself!"); + alert.showAndWait(); + }else { - for (int numberToGenerate = 0; numberToGenerate < 10; numberToGenerate++) { - Question generatedAssessment = null; - int quizType = rand.nextInt(3); - switch (quizType) { - case (0): //0 Means translation test. - //wordToTranslatePlace = rand.nextInt(Application.practiseList.size()); - //wordToTranslate = Application.practiseList.get(wordToTranslatePlace); - if((listOfAssessment.isEmpty()) || !(listOfAssessment.getLast() instanceof TranslationQuestion)){ - generatedAssessment = generateTranslationTest(practiseList); - }else { - numberToGenerate--; - } - break; - case (1): //1 Means six meanings test. - //wordToTranslatePlace = rand.nextInt(Application.practiseList.size()); - //wordToTranslate = Application.practiseList.get(wordToTranslatePlace); - if(((listOfAssessment.isEmpty())) || !(listOfAssessment.getLast() instanceof SixMeaningsQuestion)){ - generatedAssessment = generateSixMeanings(practiseList); - }else { - numberToGenerate--; - } - break; - case (2): //2 Means match meanings test. + for (int numberToGenerate = 0; numberToGenerate < 10; numberToGenerate++) { + Question generatedAssessment = null; + int quizType = rand.nextInt(3); + switch (quizType) { + case (0): //0 Means translation test. + //wordToTranslatePlace = rand.nextInt(Application.practiseList.size()); + //wordToTranslate = Application.practiseList.get(wordToTranslatePlace); + if((listOfAssessment.isEmpty()) || !(listOfAssessment.getLast() instanceof TranslationQuestion)){ + generatedAssessment = generateTranslationTest(practiseList); + }else { + numberToGenerate--; + } + break; + case (1): //1 Means six meanings test. + //wordToTranslatePlace = rand.nextInt(Application.practiseList.size()); + //wordToTranslate = Application.practiseList.get(wordToTranslatePlace); + if(((listOfAssessment.isEmpty())) || !(listOfAssessment.getLast() instanceof SixMeaningsQuestion)){ + generatedAssessment = generateSixMeanings(practiseList); + }else { + numberToGenerate--; + } + break; + case (2): //2 Means match meanings test. // LinkedList wordsToTranslate = new LinkedList<>(); // for (int i = 0; i < 3; i++) { // wordToTranslatePlace = rand.nextInt(Application.practiseList.size()); // wordsToTranslate.add(Application.practiseList.get(wordToTranslatePlace)); // wordsToTranslate.toArray(); // } - if((listOfAssessment.isEmpty()) || !(listOfAssessment.getLast() instanceof MatchTheMeaningQuestion)){ - generatedAssessment = generateMatchMeaning(practiseList); - }else { - numberToGenerate--; - } - break; - } - if(generatedAssessment != null) { - listOfAssessment.add(generatedAssessment); - } + if((listOfAssessment.isEmpty()) || !(listOfAssessment.getLast() instanceof MatchTheMeaningQuestion)){ + generatedAssessment = generateMatchMeaning(practiseList); + }else { + numberToGenerate--; + } + break; } - AssessmentGenerator.listOfAssessment = listOfAssessment; - goToNextQuestion(); - } - return listOfAssessment; - } - - /** - * Method - * that will generate a list of questions that are the type ‘Match The Meanings’, using the dictionary's - * practice words as the parameter. - * - * @return - */ - public static Question generateMatchMeaning(LinkedList practiceList) { - Random rand = new Random(); - LinkedList answerList = new LinkedList<>(); - - int successfulAnswersSelected = 0; - while (successfulAnswersSelected < 4) { - DictionaryEntry selectedAnswer; - selectedAnswer = practiceList.get(rand.nextInt(practiceList.size())); - if (answerList.contains(selectedAnswer)) { - continue; + if(generatedAssessment != null) { + listOfAssessment.add(generatedAssessment); } - answerList.add(selectedAnswer); - successfulAnswersSelected++; - } + } + AssessmentGenerator.listOfAssessment = listOfAssessment; + goToNextQuestion(); + } + return listOfAssessment; + } - return new MatchTheMeaningQuestion(answerList.toArray(DictionaryEntry[]::new)); - } + /** + * Method + * that will generate a list of questions that are the type ‘Match The Meanings’, using the dictionary's + * practice words as the parameter. + * + * @return + */ + public static Question generateMatchMeaning(LinkedList practiceList) { + Random rand = new Random(); + LinkedList answerList = new LinkedList<>(); - /** - * Method - * that will generate a list of questions that are the type ‘6 Meanings’, using the dictionary's practice - * words as the parameter. - * - * @return - */ - public static Question generateSixMeanings(LinkedList practiseList) { - Random rand = new Random(); - DictionaryEntry wordToTranslate = practiseList.get(rand.nextInt(practiseList.size())); - return new SixMeaningsQuestion(wordToTranslate, Application.dictionary); - } + int successfulAnswersSelected = 0; + while (successfulAnswersSelected < 4) { + DictionaryEntry selectedAnswer; + selectedAnswer = practiceList.get(rand.nextInt(practiceList.size())); + if (answerList.contains(selectedAnswer)) { + continue; + } + answerList.add(selectedAnswer); + successfulAnswersSelected++; + } - /** - * Method that - * will generate a list of questions that are the type ‘Translation’, using the dictionary's practice words as - * the parameter. - * - * @return - */ - public static Question generateTranslationTest(LinkedList practiceList) { - Random rand = new Random(); - DictionaryEntry selectedCorrectAnswer; - selectedCorrectAnswer = practiceList.get(rand.nextInt(practiceList.size())); - return new TranslationQuestion(selectedCorrectAnswer); - } + return new MatchTheMeaningQuestion(answerList.toArray(DictionaryEntry[]::new)); + } + + /** + * Method + * that will generate a list of questions that are the type ‘6 Meanings’, using the dictionary's practice + * words as the parameter. + * + * @return + */ + public static Question generateSixMeanings(LinkedList practiseList) { + Random rand = new Random(); + DictionaryEntry wordToTranslate = practiseList.get(rand.nextInt(practiseList.size())); + return new SixMeaningsQuestion(wordToTranslate, Application.dictionary); + } + + /** + * Method that + * will generate a list of questions that are the type ‘Translation’, using the dictionary's practice words as + * the parameter. + * + * @return + */ + public static Question generateTranslationTest(LinkedList practiceList) { + Random rand = new Random(); + DictionaryEntry selectedCorrectAnswer; + selectedCorrectAnswer = practiceList.get(rand.nextInt(practiceList.size())); + return new TranslationQuestion(selectedCorrectAnswer); + } - public static void goToNextQuestion() { - if (currentAssessment > 0){ - Question.showFeedback(); - } - if (currentAssessment < 10) { + public static void goToNextQuestion() { + if (currentAssessment > 0){ + Question.showFeedback(); + } + if (currentAssessment < 10) { - Question currentQuestion = listOfAssessment.get(currentAssessment); + Question currentQuestion = listOfAssessment.get(currentAssessment); - if (currentQuestion instanceof MatchTheMeaningQuestion) { - MatchTheMeaningController.answer = ((MatchTheMeaningQuestion) currentQuestion).getCorrectAnswer(); - ScreenSwitch.swap(ScreenSwitch.SceneEnum.matchMeaningScene); - } else if (currentQuestion instanceof SixMeaningsQuestion) { - SixMeaningsController.allQuestions = ((SixMeaningsQuestion) currentQuestion).getCorrectAnswer(); - ScreenSwitch.swap(ScreenSwitch.SceneEnum.sixMeaningScene); - } else if (currentQuestion instanceof TranslationQuestion) { - TranslationController.answer = ((TranslationQuestion) currentQuestion).getCorrectAnswer(); - ScreenSwitch.swap(ScreenSwitch.SceneEnum.translationScene); - } else { - System.err.print("The question has not been recognised"); - System.err.println(currentQuestion); - } - currentAssessment++; + if (currentQuestion instanceof MatchTheMeaningQuestion) { + MatchTheMeaningController.answer = ((MatchTheMeaningQuestion) currentQuestion).getCorrectAnswer(); + ScreenSwitch.swap(ScreenSwitch.SceneEnum.matchMeaningScene); + } else if (currentQuestion instanceof SixMeaningsQuestion) { + SixMeaningsController.allQuestions = ((SixMeaningsQuestion) currentQuestion).getCorrectAnswer(); + ScreenSwitch.swap(ScreenSwitch.SceneEnum.sixMeaningScene); + } else if (currentQuestion instanceof TranslationQuestion) { + TranslationController.answer = ((TranslationQuestion) currentQuestion).getCorrectAnswer(); + ScreenSwitch.swap(ScreenSwitch.SceneEnum.translationScene); + } else { + System.err.print("The question has not been recognised"); + System.err.println(currentQuestion); + } + currentAssessment++; - } else { + } else { - ButtonType yesBtn = new ButtonType("Yes"); - ButtonType noBtn = new ButtonType("No"); + ButtonType yesBtn = new ButtonType("Yes"); + ButtonType noBtn = new ButtonType("No"); - Alert alert = new Alert(Alert.AlertType.CONFIRMATION); - alert.setTitle("You finished the tests"); - alert.setHeaderText("You finished the tests\n Well Done!"); - alert.setResizable(false); - String sb = "You got " + - new DecimalFormat("#.##").format(((double) (totalCorrectAnswers * 100) / (double) totalAnswers)) + - "%" + - "\n Would you like to test yourself again?"; - alert.setContentText(sb); - alert.getButtonTypes().clear(); - alert.getButtonTypes().addAll(yesBtn, noBtn); + Alert alert = new Alert(Alert.AlertType.CONFIRMATION); + alert.setTitle("You finished the tests"); + alert.setHeaderText("You finished the tests\n Well Done!"); + alert.setResizable(false); + String sb = "You got " + + new DecimalFormat("#.##").format(((double) (totalCorrectAnswers * 100) / (double) totalAnswers)) + + "%" + + "\n Would you like to test yourself again?"; + alert.setContentText(sb); + alert.getButtonTypes().clear(); + alert.getButtonTypes().addAll(yesBtn, noBtn); - Optional result = alert.showAndWait(); + Optional result = alert.showAndWait(); - currentAssessment = 0; + currentAssessment = 0; - reset(); - if (result.isEmpty() || result.get() == noBtn) { - ScreenSwitch.swap(ScreenSwitch.SceneEnum.dictionaryScene); - } else { - generateAssessment(Application.practiceList); - } - } - } + reset(); + if (result.isEmpty() || result.get() == noBtn) { + ScreenSwitch.swap(ScreenSwitch.SceneEnum.dictionaryScene); + } else { + generateAssessment(Application.practiceList); + } + } + } - public static int getTotalCorrectAnswers() { - return totalCorrectAnswers; - } + public static int getTotalCorrectAnswers() { + return totalCorrectAnswers; + } - public static int getTotalAnswers() { - return totalAnswers; - } + public static int getTotalAnswers() { + return totalAnswers; + } - public static void reset(){ - totalCorrectAnswers = 0; - totalAnswers =0; - listOfAssessment = new LinkedList<>(); - currentAssessment = 0; - } + public static void reset(){ + totalCorrectAnswers = 0; + totalAnswers =0; + listOfAssessment = new LinkedList<>(); + currentAssessment = 0; + } }