Updated Assessment generator

Assessment generator now uses practice list passed to it.
Added message box at end of assessment giving a score and asking if the user wants to retry.
Updated FlashcardController to pass the practice list to the assessment generator
This commit is contained in:
law39 2020-04-29 16:02:25 +01:00
parent d8808a3b9e
commit 1858c23217
3 changed files with 149 additions and 112 deletions

View file

@ -109,7 +109,7 @@ public class FlashcardController {
@FXML
private void switchToAddWord() throws IOException {
AssessmentGenerator.generateAssessment(Application.dictionary);
AssessmentGenerator.generateAssessment(Application.practiseList);
}
}

View file

@ -1,59 +1,59 @@
package uk.ac.aber.cs22120.group20.selfassessment;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonType;
import uk.ac.aber.cs22120.group20.javafx.Application;
import uk.ac.aber.cs22120.group20.javafx.ScreenSwitch;
import uk.ac.aber.cs22120.group20.json.DictionaryEntry;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Random;
import java.util.*;
/**
* Class that contains methods to create a randomised list of questions that will
* contain a random distribution of question types.
*
* @Author
* @Version
* @See
*/
public class AssessmentGenerator {
static boolean isEnglish;
static LinkedList<Question> listOfAssessment = new LinkedList<>();
static int currentAssessment = 0;
static boolean isEnglish;
static LinkedList<Question> listOfAssessment = new LinkedList<>();
static int currentAssessment = 0;
/**
* Method that will generate a randomized list of questions consisting of random distribution of questions
* types, using the dictionarys practice words as the parameter.
* @param wordList
* @return
*/
public static LinkedList<Question> generateAssessment(LinkedList<DictionaryEntry> wordList){
LinkedList<Question> listOfAssessment = new LinkedList<>();
LinkedList<DictionaryEntry> practiseList = Application.practiseList;
Random rand = new Random();
/**
* Method that will generate a randomized list of questions consisting of random distribution of questions
* types, using the dictionarys practice words as the parameter.
*
* @param wordList
* @return
*/
public static LinkedList<Question> generateAssessment(LinkedList<DictionaryEntry> practiseList) {
LinkedList<Question> listOfAssessment = new LinkedList<>();
Random rand = new Random();
//int wordToTranslatePlace;
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);
//int wordToTranslatePlace;
generatedAssessment = generateTranslationTest(practiseList);
break;
case (1): //1 Means six meanings test.
//wordToTranslatePlace = rand.nextInt(Application.practiseList.size());
//wordToTranslate = Application.practiseList.get(wordToTranslatePlace);
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);
generatedAssessment = generateTranslationTest(practiseList);
break;
case (1): //1 Means six meanings test.
//wordToTranslatePlace = rand.nextInt(Application.practiseList.size());
//wordToTranslate = Application.practiseList.get(wordToTranslatePlace);
generatedAssessment = generateSixMeanings(practiseList);
break;
case (2): //2 Means match meanings test.
generatedAssessment = generateSixMeanings(practiseList);
break;
case (2): //2 Means match meanings test.
// LinkedList<DictionaryEntry> wordsToTranslate = new LinkedList<>();
// for (int i = 0; i < 3; i++) {
// wordToTranslatePlace = rand.nextInt(Application.practiseList.size());
@ -61,91 +61,123 @@ public class AssessmentGenerator {
// wordsToTranslate.toArray();
// }
generatedAssessment = generateMatchMeaning(practiseList);
break;
}
listOfAssessment.add(generatedAssessment);
}
AssessmentGenerator.listOfAssessment = listOfAssessment;
goToNextQuestion();
return listOfAssessment;
}
generatedAssessment = generateMatchMeaning(practiseList);
break;
}
listOfAssessment.add(generatedAssessment);
}
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<DictionaryEntry> practiceList){
Random rand = new Random();
LinkedList<DictionaryEntry> answerList = new LinkedList<>();
/**
* 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<DictionaryEntry> practiceList) {
Random rand = new Random();
LinkedList<DictionaryEntry> answerList = new LinkedList<>();
int successfulAnswersSelected = 0;
while(successfulAnswersSelected<4){
DictionaryEntry selectedAnswer;
selectedAnswer = practiceList.get(rand.nextInt(practiceList.size()-1));
if (answerList.contains(selectedAnswer)){
continue;
}
answerList.add(selectedAnswer);
successfulAnswersSelected++;
}
int successfulAnswersSelected = 0;
while (successfulAnswersSelected < 4) {
DictionaryEntry selectedAnswer;
selectedAnswer = practiceList.get(rand.nextInt(practiceList.size()));
if (answerList.contains(selectedAnswer)) {
continue;
}
answerList.add(selectedAnswer);
successfulAnswersSelected++;
}
Question generatedQuestion = new MatchTheMeaningQuestion(answerList.toArray(DictionaryEntry[]::new));
return generatedQuestion;
}
Question generatedQuestion = new MatchTheMeaningQuestion(answerList.toArray(DictionaryEntry[]::new));
return generatedQuestion;
}
/**
* 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<DictionaryEntry> practiseList){
Question returnValue;
ArrayList<DictionaryEntry> listOfAnswers = new ArrayList<>();
Random rand = new Random();
DictionaryEntry wordToTranslate = practiseList.get(rand.nextInt(practiseList.size() - 1));
SixMeaningsQuestion generatedQuestion = new SixMeaningsQuestion(wordToTranslate, Application.dictionary);
return generatedQuestion;
}
/**
* 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<DictionaryEntry> practiseList) {
Question returnValue;
ArrayList<DictionaryEntry> listOfAnswers = new ArrayList<>();
Random rand = new Random();
DictionaryEntry wordToTranslate = practiseList.get(rand.nextInt(practiseList.size()));
SixMeaningsQuestion generatedQuestion = new SixMeaningsQuestion(wordToTranslate, Application.dictionary);
return generatedQuestion;
}
/**
* 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<DictionaryEntry> practiceList){
Random rand = new Random();
DictionaryEntry selectedCorrectAnswer;
selectedCorrectAnswer = practiceList.get(rand.nextInt(practiceList.size()-1));
Question generatedQuestion = new TranslationQuestion(selectedCorrectAnswer);
return generatedQuestion;
}
/**
* 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<DictionaryEntry> practiceList) {
Random rand = new Random();
DictionaryEntry selectedCorrectAnswer;
selectedCorrectAnswer = practiceList.get(rand.nextInt(practiceList.size()));
Question generatedQuestion = new TranslationQuestion(selectedCorrectAnswer);
return generatedQuestion;
}
public static void goToNextQuestion(){
public static void goToNextQuestion() {
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);
}
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 {
currentAssessment++;
StringBuilder sb = new StringBuilder();
sb.append("You scored: ")
.append(Question.correctAnswers).append("/")
.append(Question.correctAnswers + Question.wrongAnswers)
.append("\n Would you like to test yourself again?");
}
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);
alert.setContentText(sb.toString());
Optional<ButtonType> result = alert.showAndWait();
((Button) alert.getDialogPane().lookupButton(ButtonType.OK)).setText("Yes");
((Button) alert.getDialogPane().lookupButton(ButtonType.CANCEL)).setText("No");
if (result.isEmpty() || result.get() == ButtonType.CANCEL) {
currentAssessment=0;
Question.resetScore();
ScreenSwitch.swap(ScreenSwitch.SceneEnum.dictionaryScene);
} else {
currentAssessment = 0;
Question.resetScore();
generateAssessment(Application.practiseList);
}
}
}
}

View file

@ -38,6 +38,11 @@ public class Question {
}else wrongAnswers++;
}
}
}
public static void resetScore(){
correctAnswers = 0;
wrongAnswers =0;
}
}
}