Updated AssessmentGenerator

Assessment Generator now controls the switching of assessments and the setup of assessments.
This commit is contained in:
law39 2020-04-29 13:24:52 +01:00
parent ff27d91b81
commit 98dfa72e40

View file

@ -1,10 +1,15 @@
package uk.ac.aber.cs22120.group20.selfassessment;
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;
/**
* Class that contains methods to create a randomised list of questions that will
* contain a random distribution of question types.
@ -14,7 +19,8 @@ import java.util.Random;
*/
public class AssessmentGenerator {
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
@ -29,7 +35,7 @@ public class AssessmentGenerator {
int wordToTranslatePlace;
//int wordToTranslatePlace;
for (int numberToGenerate = 0; numberToGenerate < 10; numberToGenerate++) {
Question generatedAssessment = null;
@ -60,7 +66,7 @@ public class AssessmentGenerator {
}
listOfAssessment.add(generatedAssessment);
}
AssessmentGenerator.listOfAssessment = listOfAssessment;
return listOfAssessment;
}
@ -72,11 +78,21 @@ public class AssessmentGenerator {
*/
public static Question generateMatchMeaning(LinkedList<DictionaryEntry> practiceList){
Random rand = new Random();
DictionaryEntry selectedCorrectAnswer;
selectedCorrectAnswer = practiceList.get(rand.nextInt(practiceList.size()-1));
Question generatedQuestion = new TranslationQuestion(selectedCorrectAnswer);
return generatedQuestion;
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++;
}
Question generatedQuestion = new MatchTheMeaningQuestion(answerList.toArray(DictionaryEntry[]::new));
return generatedQuestion;
}
/**
@ -86,45 +102,12 @@ public class AssessmentGenerator {
* @return
*/
public static Question generateSixMeanings(LinkedList<DictionaryEntry> practiseList){
//CHANGE DICTIONARY TO PRACTISE LIST
Question returnValue;
ArrayList<DictionaryEntry> listOfAnswers = new ArrayList<>();
Random rand = new Random();
boolean isDuplicate = false;
do{
int rand_q=rand.nextInt(Application.dictionary.size()-1);
DictionaryEntry pickedQuestion = Application.dictionary.get(rand_q);
//If size of list is greater than 1 check for duplicates...
if(MatchTheMeaningQuestion.setOfQuestions.size()>=1){
for (DictionaryEntry setOfQuestion : MatchTheMeaningQuestion.setOfQuestions) {
//If it is duplicate change isDuplicate to true and break
if (setOfQuestion.equals(pickedQuestion)) {
isDuplicate = true;
break;
}
}
//If duplicate wasn't found add entry to the list
if(!isDuplicate){
MatchTheMeaningQuestion.setOfQuestions.add(pickedQuestion);
}
//... otherwise, add entry to the
}else{
MatchTheMeaningQuestion.setOfQuestions.add(pickedQuestion);
}
isDuplicate =false;
}while(MatchTheMeaningQuestion.setOfQuestions.size()<5);
DictionaryEntry wordToTranslate = practiseList.get(rand.nextInt(practiseList.size() - 1));
SixMeaningsQuestion generatedQuestion = new SixMeaningsQuestion(wordToTranslate, Application.dictionary);
return generatedQuestion;
}
/**
@ -143,7 +126,24 @@ public class AssessmentGenerator {
public static void goToNextQuestion(){
Question currentQuestion = listOfAssessment.get(currentAssessment);
if(currentQuestion instanceof MatchTheMeaningQuestion){
MatchTheMeaningController.answer = (ArrayList<DictionaryEntry>) Arrays.asList(((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);
}
}
}