Fixed issues with selfassessment package
This commit is contained in:
parent
e523f0f21a
commit
9d4eb318f1
5 changed files with 46 additions and 26 deletions
|
@ -32,7 +32,7 @@ import java.util.*;
|
||||||
* @see MatchTheMeaningController
|
* @see MatchTheMeaningController
|
||||||
*/
|
*/
|
||||||
public class AssessmentGenerator {
|
public class AssessmentGenerator {
|
||||||
public static boolean isEnglish;
|
public static boolean isEnglishList;
|
||||||
static LinkedList<Question> listOfAssessment = new LinkedList<>();
|
static LinkedList<Question> listOfAssessment = new LinkedList<>();
|
||||||
static int currentAssessment = 0;
|
static int currentAssessment = 0;
|
||||||
static int totalCorrectAnswers = 0;
|
static int totalCorrectAnswers = 0;
|
||||||
|
@ -51,8 +51,6 @@ public class AssessmentGenerator {
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
|
|
||||||
//int wordToTranslatePlace;
|
|
||||||
|
|
||||||
if (practiseList.size()<5){
|
if (practiseList.size()<5){
|
||||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||||
alert.setTitle("Error");
|
alert.setTitle("Error");
|
||||||
|
@ -67,8 +65,6 @@ public class AssessmentGenerator {
|
||||||
int quizType = rand.nextInt(3);
|
int quizType = rand.nextInt(3);
|
||||||
switch (quizType) {
|
switch (quizType) {
|
||||||
case (0): //0 Means translation test.
|
case (0): //0 Means translation test.
|
||||||
//wordToTranslatePlace = rand.nextInt(Application.practiseList.size());
|
|
||||||
//wordToTranslate = Application.practiseList.get(wordToTranslatePlace);
|
|
||||||
if((listOfAssessment.isEmpty()) || !(listOfAssessment.getLast() instanceof TranslationQuestion)){
|
if((listOfAssessment.isEmpty()) || !(listOfAssessment.getLast() instanceof TranslationQuestion)){
|
||||||
generatedAssessment = generateTranslationTest(practiseList);
|
generatedAssessment = generateTranslationTest(practiseList);
|
||||||
}else {
|
}else {
|
||||||
|
@ -76,8 +72,6 @@ public class AssessmentGenerator {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case (1): //1 Means six meanings test.
|
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)){
|
if(((listOfAssessment.isEmpty())) || !(listOfAssessment.getLast() instanceof SixMeaningsQuestion)){
|
||||||
generatedAssessment = generateSixMeanings(practiseList);
|
generatedAssessment = generateSixMeanings(practiseList);
|
||||||
}else {
|
}else {
|
||||||
|
@ -85,12 +79,6 @@ public class AssessmentGenerator {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case (2): //2 Means match meanings test.
|
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)){
|
if((listOfAssessment.isEmpty()) || !(listOfAssessment.getLast() instanceof MatchTheMeaningQuestion)){
|
||||||
generatedAssessment = generateMatchMeaning(practiseList);
|
generatedAssessment = generateMatchMeaning(practiseList);
|
||||||
}else {
|
}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() {
|
public static void goToNextQuestion() {
|
||||||
if (currentAssessment > 0){
|
if (currentAssessment > 0){
|
||||||
Question.showFeedback();
|
Question.showFeedback();
|
||||||
|
@ -224,6 +216,9 @@ public class AssessmentGenerator {
|
||||||
return totalAnswers;
|
return totalAnswers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method for resetting assessment to default state.
|
||||||
|
*/
|
||||||
public static void reset(){
|
public static void reset(){
|
||||||
totalCorrectAnswers = 0;
|
totalCorrectAnswers = 0;
|
||||||
totalAnswers =0;
|
totalAnswers =0;
|
||||||
|
|
|
@ -6,7 +6,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class used to create a MatchTheMeaning Question.
|
* Class used to generate a MatchTheMeaning Question.
|
||||||
* @author Brad Corbett [brc9]
|
* @author Brad Corbett [brc9]
|
||||||
* @author Henry Dugmore [hjd3]
|
* @author Henry Dugmore [hjd3]
|
||||||
* @author Kain Bryan-Jones [kab74]
|
* @author Kain Bryan-Jones [kab74]
|
||||||
|
@ -18,15 +18,20 @@ import java.util.Arrays;
|
||||||
* @version 0.1 Initial development
|
* @version 0.1 Initial development
|
||||||
* @see Question
|
* @see Question
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
public class MatchTheMeaningQuestion extends Question {
|
public class MatchTheMeaningQuestion extends Question {
|
||||||
private final ArrayList<DictionaryEntry> correctAnswer = new ArrayList<>();
|
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){
|
public MatchTheMeaningQuestion(DictionaryEntry[] correctAnswer){
|
||||||
this.correctAnswer.addAll(Arrays.asList(correctAnswer));
|
this.correctAnswer.addAll(Arrays.asList(correctAnswer));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return ArrayList of DictionaryEntry objects storing correctAnswers
|
||||||
|
*/
|
||||||
public ArrayList<DictionaryEntry> getCorrectAnswer() {
|
public ArrayList<DictionaryEntry> getCorrectAnswer() {
|
||||||
return correctAnswer;
|
return correctAnswer;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,10 @@ public class Question {
|
||||||
public static int wrongAnswers =0;
|
public static int wrongAnswers =0;
|
||||||
public static StringBuilder sb = new StringBuilder();
|
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 listOfCorrectQuestions List of the right answers to the question.
|
||||||
* @param listOfAnswers List of the answers the user input.
|
* @param listOfAnswers List of the answers the user input.
|
||||||
* @param isEnglish Boolean for if the test is English To Welsh or Welsh To English
|
* @param isEnglish Boolean for if the test is English To Welsh or Welsh To English
|
||||||
|
@ -38,11 +40,20 @@ public class Question {
|
||||||
if(isEnglish){
|
if(isEnglish){
|
||||||
for(int i=0; i<listOfCorrectQuestions.size();i++){
|
for(int i=0; i<listOfCorrectQuestions.size();i++){
|
||||||
|
|
||||||
|
//Build first part of the sentence
|
||||||
|
//i.e. "englishWord is the English for welshWord "
|
||||||
sb
|
sb
|
||||||
.append("'").append(listOfCorrectQuestions.get(i).getEnglish()).append("'")
|
.append("'").append(listOfCorrectQuestions.get(i).getEnglish()).append("'")
|
||||||
.append(" is the English for ")
|
.append(" is the English for ")
|
||||||
.append("'").append(listOfCorrectQuestions.get(i).getWelsh()).append("'")
|
.append("'").append(listOfCorrectQuestions.get(i).getWelsh()).append("'")
|
||||||
.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))){
|
if(listOfCorrectQuestions.get(i).getWelsh().equals(listOfAnswers.get(i))){
|
||||||
sb.append("Correct!");
|
sb.append("Correct!");
|
||||||
correctAnswers++;
|
correctAnswers++;
|
||||||
|
@ -55,9 +66,9 @@ public class Question {
|
||||||
}else{
|
}else{
|
||||||
for(int i=0; i<listOfCorrectQuestions.size();i++){
|
for(int i=0; i<listOfCorrectQuestions.size();i++){
|
||||||
sb
|
sb
|
||||||
.append("'").append(listOfCorrectQuestions.get(i).getEnglish()).append("'")
|
|
||||||
.append(" is the English for ")
|
|
||||||
.append("'").append(listOfCorrectQuestions.get(i).getWelsh()).append("'")
|
.append("'").append(listOfCorrectQuestions.get(i).getWelsh()).append("'")
|
||||||
|
.append(" is the Welsh for ")
|
||||||
|
.append("'").append(listOfCorrectQuestions.get(i).getEnglish()).append("'")
|
||||||
.append(". ");
|
.append(". ");
|
||||||
|
|
||||||
if(listOfCorrectQuestions.get(i).getEnglish().equals(listOfAnswers.get(i))){
|
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.
|
* Function for giving user positive or negative feedback for when they answer a question during an assessment.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void showFeedback(){
|
static void showFeedback(){
|
||||||
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
||||||
|
|
||||||
|
|
|
@ -23,23 +23,30 @@ public class SixMeaningsQuestion extends Question{
|
||||||
private final DictionaryEntry correctAnswer;
|
private final DictionaryEntry correctAnswer;
|
||||||
private final LinkedList<DictionaryEntry> dictionary;
|
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) {
|
public SixMeaningsQuestion(DictionaryEntry correctAnswer, LinkedList<DictionaryEntry> dictionary) {
|
||||||
this.correctAnswer = correctAnswer;
|
this.correctAnswer = correctAnswer;
|
||||||
this.dictionary = dictionary;
|
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
|
* @return Retrieves the correct answer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public ArrayList<DictionaryEntry> getCorrectAnswer() {
|
public ArrayList<DictionaryEntry> getCorrectAnswer() {
|
||||||
Random rand = new Random();
|
Random rand = new Random();
|
||||||
|
|
||||||
|
|
||||||
ArrayList<DictionaryEntry> result = new ArrayList<>();
|
ArrayList<DictionaryEntry> result = new ArrayList<>();
|
||||||
|
|
||||||
result.add(correctAnswer);
|
result.add(correctAnswer);
|
||||||
int successfulAnswersSelected = 0;
|
int successfulAnswersSelected = 0;
|
||||||
|
|
||||||
|
|
||||||
while(successfulAnswersSelected<5){
|
while(successfulAnswersSelected<5){
|
||||||
DictionaryEntry selectedAnswer;
|
DictionaryEntry selectedAnswer;
|
||||||
selectedAnswer = dictionary.get(rand.nextInt(dictionary.size()-1));
|
selectedAnswer = dictionary.get(rand.nextInt(dictionary.size()-1));
|
||||||
|
@ -49,8 +56,6 @@ public class SixMeaningsQuestion extends Question{
|
||||||
result.add(selectedAnswer);
|
result.add(selectedAnswer);
|
||||||
successfulAnswersSelected++;
|
successfulAnswersSelected++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,10 @@ import uk.ac.aber.cs22120.group20.json.DictionaryEntry;
|
||||||
public class TranslationQuestion extends Question {
|
public class TranslationQuestion extends Question {
|
||||||
private final DictionaryEntry correctAnswer;
|
private final DictionaryEntry correctAnswer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor for translation question
|
||||||
|
* @param correctAnswer the correct answer of translation guess.
|
||||||
|
*/
|
||||||
public TranslationQuestion(DictionaryEntry correctAnswer){
|
public TranslationQuestion(DictionaryEntry correctAnswer){
|
||||||
this.correctAnswer = correctAnswer;
|
this.correctAnswer = correctAnswer;
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue