Fixed issues with selfassessment package

This commit is contained in:
kab74 2020-05-01 13:31:43 +01:00
parent e523f0f21a
commit 9d4eb318f1
5 changed files with 46 additions and 26 deletions

View file

@ -32,7 +32,7 @@ import java.util.*;
* @see MatchTheMeaningController
*/
public class AssessmentGenerator {
public static boolean isEnglish;
public static boolean isEnglishList;
static LinkedList<Question> listOfAssessment = new LinkedList<>();
static int currentAssessment = 0;
static int totalCorrectAnswers = 0;
@ -51,8 +51,6 @@ public class AssessmentGenerator {
reset();
//int wordToTranslatePlace;
if (practiseList.size()<5){
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error");
@ -67,8 +65,6 @@ public class AssessmentGenerator {
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 {
@ -76,8 +72,6 @@ public class AssessmentGenerator {
}
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 {
@ -85,12 +79,6 @@ public class AssessmentGenerator {
}
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());
// wordsToTranslate.add(Application.practiseList.get(wordToTranslatePlace));
// wordsToTranslate.toArray();
// }
if((listOfAssessment.isEmpty()) || !(listOfAssessment.getLast() instanceof MatchTheMeaningQuestion)){
generatedAssessment = generateMatchMeaning(practiseList);
}else {
@ -161,6 +149,10 @@ public class AssessmentGenerator {
}
/**
* Method uses currentAssessment as pointer to go to next question in assessment list.
* Uses a switch case statement to choose the appropriate type of question.
*/
public static void goToNextQuestion() {
if (currentAssessment > 0){
Question.showFeedback();
@ -224,6 +216,9 @@ public class AssessmentGenerator {
return totalAnswers;
}
/**
* Method for resetting assessment to default state.
*/
public static void reset(){
totalCorrectAnswers = 0;
totalAnswers =0;

View file

@ -6,7 +6,7 @@ import java.util.ArrayList;
import java.util.Arrays;
/**
* Class used to create a MatchTheMeaning Question.
* Class used to generate a MatchTheMeaning Question.
* @author Brad Corbett [brc9]
* @author Henry Dugmore [hjd3]
* @author Kain Bryan-Jones [kab74]
@ -18,15 +18,20 @@ import java.util.Arrays;
* @version 0.1 Initial development
* @see Question
*/
public class MatchTheMeaningQuestion extends Question {
private final ArrayList<DictionaryEntry> correctAnswer = new ArrayList<>();
/**
* Default constructer which loads ArrayList into correctAnswer field variable.
* @param correctAnswer the ArrayList of DictionaryEntry objects
*/
public MatchTheMeaningQuestion(DictionaryEntry[] correctAnswer){
this.correctAnswer.addAll(Arrays.asList(correctAnswer));
}
/**
* @return ArrayList of DictionaryEntry objects storing correctAnswers
*/
public ArrayList<DictionaryEntry> getCorrectAnswer() {
return correctAnswer;
}

View file

@ -27,8 +27,10 @@ public class Question {
public static int wrongAnswers =0;
public static StringBuilder sb = new StringBuilder();
/** Function that checks the answers of
*
/** Function that checks the answers of questions. Checks whether they're right and
* uses an object instance of StringBuilder to build an appropriate sentence to present to the user to give
* them their feedback.
* E.g. "Apple is the English for Afal is correct"
* @param listOfCorrectQuestions List of the right answers to the question.
* @param listOfAnswers List of the answers the user input.
* @param isEnglish Boolean for if the test is English To Welsh or Welsh To English
@ -38,11 +40,20 @@ public class Question {
if(isEnglish){
for(int i=0; i<listOfCorrectQuestions.size();i++){
//Build first part of the sentence
//i.e. "englishWord is the English for welshWord "
sb
.append("'").append(listOfCorrectQuestions.get(i).getEnglish()).append("'")
.append(" is the English for ")
.append("'").append(listOfCorrectQuestions.get(i).getWelsh()).append("'")
.append(". ");
/*
* If the sentence currently makes sense, such as 'apple is the english for apple' then
* this next code will append the term either 'is correct' or 'is incorrect'.
* To do this it uses index i to get the welsh word of the correct answer.
* It then compares that word to the word at index i in the listOfAnswers.
* Depending on whether they are eqaual it will append 'correct' or 'incorrect'.
*/
if(listOfCorrectQuestions.get(i).getWelsh().equals(listOfAnswers.get(i))){
sb.append("Correct!");
correctAnswers++;
@ -55,9 +66,9 @@ public class Question {
}else{
for(int i=0; i<listOfCorrectQuestions.size();i++){
sb
.append("'").append(listOfCorrectQuestions.get(i).getEnglish()).append("'")
.append(" is the English for ")
.append("'").append(listOfCorrectQuestions.get(i).getWelsh()).append("'")
.append(" is the Welsh for ")
.append("'").append(listOfCorrectQuestions.get(i).getEnglish()).append("'")
.append(". ");
if(listOfCorrectQuestions.get(i).getEnglish().equals(listOfAnswers.get(i))){
@ -74,10 +85,10 @@ public class Question {
}
/**
* Function for giving user positive or negative feedback for when they answer a question during an assessment.
*/
static void showFeedback(){
Alert alert = new Alert(Alert.AlertType.INFORMATION);

View file

@ -23,23 +23,30 @@ public class SixMeaningsQuestion extends Question{
private final DictionaryEntry correctAnswer;
private final LinkedList<DictionaryEntry> dictionary;
/**
* Default constructor for SixMeaningsQuestion.
* @param correctAnswer the correct answer for the list of questions.
* @param dictionary the list of questions the user will have to pick between
*/
public SixMeaningsQuestion(DictionaryEntry correctAnswer, LinkedList<DictionaryEntry> dictionary) {
this.correctAnswer = correctAnswer;
this.dictionary = dictionary;
}
/** Function to retrieve the correct answer to a SixMeaningsQuestion.
*
/**
* Function to retrieve the correct answer to a SixMeaningsQuestion
* @return Retrieves the correct answer
*/
public ArrayList<DictionaryEntry> getCorrectAnswer() {
Random rand = new Random();
ArrayList<DictionaryEntry> result = new ArrayList<>();
result.add(correctAnswer);
int successfulAnswersSelected = 0;
while(successfulAnswersSelected<5){
DictionaryEntry selectedAnswer;
selectedAnswer = dictionary.get(rand.nextInt(dictionary.size()-1));
@ -49,8 +56,6 @@ public class SixMeaningsQuestion extends Question{
result.add(selectedAnswer);
successfulAnswersSelected++;
}
return result;
}
}

View file

@ -19,6 +19,10 @@ import uk.ac.aber.cs22120.group20.json.DictionaryEntry;
public class TranslationQuestion extends Question {
private final DictionaryEntry correctAnswer;
/**
* Default constructor for translation question
* @param correctAnswer the correct answer of translation guess.
*/
public TranslationQuestion(DictionaryEntry correctAnswer){
this.correctAnswer = correctAnswer;
}