This commit is contained in:
osp1 2020-04-29 12:26:16 +01:00
commit b4577b99f4
9 changed files with 109 additions and 117 deletions

View file

@ -84,7 +84,9 @@ public class DictionaryEntry {
this.practiceWord = practiceWord; this.practiceWord = practiceWord;
} }
public boolean equals(DictionaryEntry entry) { @Override
return entry.getEnglish().equals(this.getEnglish()) && entry.getWelsh().equals(this.getWelsh()) && entry.getWordType().equals(this.getWordType()); public boolean equals(Object entry) {
DictionaryEntry otherEntry = (DictionaryEntry) entry;
return otherEntry.getEnglish().equals(this.getEnglish()) && otherEntry.getWelsh().equals(this.getWelsh()) && otherEntry.getWordType().equals(this.getWordType());
} }
} }

View file

@ -74,7 +74,7 @@ public class AssessmentGenerator {
Random rand = new Random(); Random rand = new Random();
DictionaryEntry selectedCorrectAnswer; DictionaryEntry selectedCorrectAnswer;
selectedCorrectAnswer = practiceList.get(rand.nextInt(practiceList.size()-1)); selectedCorrectAnswer = practiceList.get(rand.nextInt(practiceList.size()-1));
TranslationQuestion generatedQuestion = new TranslationQuestion(selectedCorrectAnswer); Question generatedQuestion = new TranslationQuestion(selectedCorrectAnswer);
return generatedQuestion; return generatedQuestion;
} }
@ -133,9 +133,17 @@ public class AssessmentGenerator {
* the parameter. * the parameter.
* @return * @return
*/ */
public static Question generateTranslationTest(LinkedList<DictionaryEntry> a){ public static Question generateTranslationTest(LinkedList<DictionaryEntry> practiceList){
return null; Random rand = new Random();
DictionaryEntry selectedCorrectAnswer;
selectedCorrectAnswer = practiceList.get(rand.nextInt(practiceList.size()-1));
Question generatedQuestion = new TranslationQuestion(selectedCorrectAnswer);
return generatedQuestion;
} }
public static void goToNextQuestion(){
}
} }

View file

@ -33,7 +33,7 @@ import java.util.*;
public class MatchTheMeaningController extends Question implements Initializable{ public class MatchTheMeaningController extends Question implements Initializable{
private ArrayList<DictionaryEntry> setOfQuestions=new ArrayList<>(); private ArrayList<DictionaryEntry> answer =new ArrayList<>();
private ArrayList<Integer> orderList = new ArrayList<>(Arrays.asList(0,1,2,3)); private ArrayList<Integer> orderList = new ArrayList<>(Arrays.asList(0,1,2,3));
private boolean isEnglish; private boolean isEnglish;
@ -86,7 +86,7 @@ public class MatchTheMeaningController extends Question implements Initializable
*/ */
private void getQuestions(){ private void getQuestions(){
setOfQuestions.addAll(AssessmentGenerator.generateWordMatch()); answer.addAll(AssessmentGenerator.generateWordMatch());
} }
@ -147,12 +147,12 @@ public class MatchTheMeaningController extends Question implements Initializable
listOfAnswers.add(LeftWord4.getText()); listOfAnswers.add(LeftWord4.getText());
} }
checkAnswer(setOfQuestions,listOfAnswers,isEnglish); checkAnswer(answer,listOfAnswers,isEnglish);
CorrectAnswer.setText(Integer.toString(correctAnswers)); CorrectAnswer.setText(Integer.toString(correctAnswers));
WrongAnswer.setText(Integer.toString(wrongAnswers)); WrongAnswer.setText(Integer.toString(wrongAnswers));
setOfQuestions.clear(); answer.clear();
this.prepare(); this.prepare();
} }
@ -162,7 +162,7 @@ public class MatchTheMeaningController extends Question implements Initializable
*/ */
private void prepare(){ private void prepare(){
getQuestions(); getQuestions();
setWords(setOfQuestions,orderList); setWords(answer,orderList);
} }
@Override @Override

View file

@ -3,11 +3,13 @@ package uk.ac.aber.cs22120.group20.selfassessment;
import uk.ac.aber.cs22120.group20.json.DictionaryEntry; import uk.ac.aber.cs22120.group20.json.DictionaryEntry;
public class MatchTheMeaningQuestion extends Question { public class MatchTheMeaningQuestion extends Question {
DictionaryEntry[] correctAnswer; private DictionaryEntry[] correctAnswer;
public MatchTheMeaningQuestion(DictionaryEntry[] correctAnswer){ public MatchTheMeaningQuestion(DictionaryEntry[] correctAnswer){
this.correctAnswer = correctAnswer; this.correctAnswer = correctAnswer;
} }
public DictionaryEntry[] getCorrectAnswer() {
return correctAnswer;
}
} }

View file

@ -35,11 +35,11 @@ import java.util.*;
public class SixMeaningsController extends TranslationController implements Initializable { public class SixMeaningsController extends TranslationController implements Initializable {
private Random rand = new Random(); private Random rand = new Random();
private LinkedList<DictionaryEntry> wordSet = new LinkedList<>(); private ArrayList<DictionaryEntry> wordSet = new ArrayList<>();
private ArrayList<DictionaryEntry> tamp = new ArrayList<>();
private ArrayList<Integer> orderList = new ArrayList<>(Arrays.asList(0, 1, 2, 3, 4, 5)); private ArrayList<Integer> orderList = new ArrayList<>(Arrays.asList(0, 1, 2, 3, 4, 5));
private int correct = 0;
private int incorrect = 0;
private String wordCounterpart; private String wordCounterpart;
private boolean isEnglish = AssessmentGenerator.isEnglish;
@FXML @FXML
@ -70,126 +70,98 @@ public class SixMeaningsController extends TranslationController implements Init
private Text possibleAnswer6; private Text possibleAnswer6;
@FXML @FXML
void temp(MouseEvent event) { void answer1(MouseEvent event) {
wordCounterpart = possibleAnswer1.getText();
checkAnswers();
}
@FXML
void answer2(MouseEvent event) {
wordCounterpart = possibleAnswer2.getText();
checkAnswers();
}
@FXML
void answer3(MouseEvent event) {
wordCounterpart = possibleAnswer3.getText();
checkAnswers();
}
@FXML
void answer4(MouseEvent event) {
wordCounterpart = possibleAnswer4.getText();
checkAnswers();
}
@FXML
void answer5(MouseEvent event) {
wordCounterpart = possibleAnswer5.getText();
checkAnswers();
}
@FXML
void answer6(MouseEvent event) {
wordCounterpart = possibleAnswer6.getText();
checkAnswers(); checkAnswers();
} }
private void getWords(LinkedList<DictionaryEntry> practiceList) { private void getWords() {
boolean isDuplicate = false;
do {
int word = rand.nextInt(practiceList.size() - 1);
DictionaryEntry chosenWord = practiceList.get(word);
if (wordSet.size() >= 1) { wordSet = AssessmentGenerator.generateSixMeanings();
for (DictionaryEntry setOfQuestion : wordSet) {
if (setOfQuestion.equals(chosenWord)) {
isDuplicate = true;
break;
}
}
//If duplicate wasn't found add entry to the list
if (!isDuplicate) {
wordSet.add(chosenWord);
}
//... otherwise, add entry to the
} else {
wordSet.add(chosenWord);
}
isDuplicate = false;
} while (wordSet.size() < 6);
} }
private void setWordsE(LinkedList<DictionaryEntry> questions, ArrayList<Integer> orderList) {
//WelshWord1 Is the question word and as a result is always right.
wordToTranslate.setText(questions.get(0).getWelsh());
//This stores the correct answer for the english word.
wordCounterpart = questions.get(0).getEnglish();
possibleAnswer1.setText(questions.get(orderList.get(0)).getEnglish());
possibleAnswer2.setText(questions.get(orderList.get(1)).getEnglish());
possibleAnswer3.setText(questions.get(orderList.get(2)).getEnglish());
possibleAnswer4.setText(questions.get(orderList.get(3)).getEnglish());
possibleAnswer5.setText(questions.get(orderList.get(4)).getEnglish());
possibleAnswer6.setText(questions.get(orderList.get(5)).getEnglish());
Collections.shuffle(orderList); //I know that this does not belong here it was moved here for debug purposes. It lives five lines up. private void setWords(boolean isEnglish){
} if(isEnglish){
//WelshWord1 Is the question word and as a result is always right.
wordToTranslate.setText(questions.get(0).getEnglish());
//This stores the correct answer for the english word.
possibleAnswer1.setText(questions.get(orderList.get(0)).getWelsh());
possibleAnswer2.setText(questions.get(orderList.get(1)).getWelsh());
possibleAnswer3.setText(questions.get(orderList.get(2)).getWelsh());
possibleAnswer4.setText(questions.get(orderList.get(3)).getWelsh());
possibleAnswer5.setText(questions.get(orderList.get(4)).getWelsh());
possibleAnswer6.setText(questions.get(orderList.get(5)).getWelsh());
private void setWordsW(LinkedList<DictionaryEntry> questions, ArrayList<Integer> orderList) { Collections.shuffle(orderList); //I know that this does not belong here it was moved here for debug purposes. It lives five lines up.
//WelshWord1 Is the question word and as a result is always right. }else {
wordToTranslate.setText(questions.get(0).getEnglish()); //WelshWord1 Is the question word and as a result is always right.
//This stores the correct answer for the english word. wordToTranslate.setText(questions.get(0).getWelsh());
wordCounterpart = questions.get(0).getWelsh(); //This stores the correct answer for the english word.
possibleAnswer1.setText(questions.get(orderList.get(0)).getWelsh()); possibleAnswer1.setText(questions.get(orderList.get(0)).getEnglish());
possibleAnswer2.setText(questions.get(orderList.get(1)).getWelsh()); possibleAnswer2.setText(questions.get(orderList.get(1)).getEnglish());
possibleAnswer3.setText(questions.get(orderList.get(2)).getWelsh()); possibleAnswer3.setText(questions.get(orderList.get(2)).getEnglish());
possibleAnswer4.setText(questions.get(orderList.get(3)).getWelsh()); possibleAnswer4.setText(questions.get(orderList.get(3)).getEnglish());
possibleAnswer5.setText(questions.get(orderList.get(4)).getWelsh()); possibleAnswer5.setText(questions.get(orderList.get(4)).getEnglish());
possibleAnswer6.setText(questions.get(orderList.get(5)).getWelsh()); possibleAnswer6.setText(questions.get(orderList.get(5)).getEnglish());
Collections.shuffle(orderList); //I know that this does not belong here it was moved here for debug purposes. It lives five lines up.
}
Collections.shuffle(orderList); //I know that this does not belong here it was moved here for debug purposes. It lives five lines up.
} }
public void checkAnswers() {
String option1 = possibleAnswer1.toString();
String option2 = possibleAnswer2.toString();
String option3 = possibleAnswer3.toString();
String option4 = possibleAnswer4.toString();
String option5 = possibleAnswer5.toString();
String option6 = possibleAnswer6.toString();
if (option1 == wordCounterpart) { private void checkAnswers() {
correct++;
} else incorrect++;
if (option2 == wordCounterpart) { ArrayList<String> answer = new ArrayList<>();
correct++;
} else incorrect++;
if (option3 == wordCounterpart) { answer.add(wordCounterpart);
correct++;
} else incorrect++;
if (option4 == wordCounterpart) { checkAnswer(wordSet,answer,isEnglish);
correct++;
} else incorrect++;
if (option5 == wordCounterpart) { correctAnswer.setText(Integer.toString(Question.correctAnswers));
correct++;
} else incorrect++;
if (option6 == wordCounterpart) { wrongAnswer.setText(Integer.toString(Question.wrongAnswers));
correct++;
} else incorrect++;
correctAnswer.setText(Integer.toString(correct));
wrongAnswer.setText(Integer.toString(incorrect));
wordSet.clear(); wordSet.clear();
this.prepare();
} }
private void prepare() { private void prepare() {
getWords(Application.dictionary); getWords();
Random rd = new Random(); Random rd = new Random();
System.out.println(rd.nextBoolean()); System.out.println(rd.nextBoolean());
if (rd.nextBoolean() == true) { setWords(AssessmentGenerator.isEnglish);
setWordsE(wordSet, orderList);
} else setWordsW(wordSet, orderList);
} }

View file

@ -12,4 +12,8 @@ public class SixMeaningsQuestion extends Question{
this.correctAnswer = correctAnswer; this.correctAnswer = correctAnswer;
this.dictionary = dictionary; this.dictionary = dictionary;
} }
public DictionaryEntry getCorrectAnswer() {
return correctAnswer;
}
} }

View file

@ -18,12 +18,12 @@ import uk.ac.aber.cs22120.group20.javafx.Application;
* Controller for the translationTest fxml file. * Controller for the translationTest fxml file.
* *
* @author Brad Corbett brc9 * @author Brad Corbett brc9
* @version 0.9 * @version 0.1
* *
*/ */
public class TranslationController extends Question { public class TranslationController extends Question {
private ArrayList<DictionaryEntry> practiceList = new ArrayList<>(); private ArrayList<DictionaryEntry> practiceList = new ArrayList<>();
public static DictionaryEntry practiceWord = new DictionaryEntry(); public static DictionaryEntry answer = new DictionaryEntry();
/** /**
* Represents the word that will be randomly chosen from the practiceList. * Represents the word that will be randomly chosen from the practiceList.
@ -67,10 +67,10 @@ public class TranslationController extends Question {
if(AssessmentGenerator.isEnglish){ if(AssessmentGenerator.isEnglish){
wordToTranslate.setText(practiceWord.getWelsh()); wordToTranslate.setText(answer.getWelsh());
} }
else{ else{
wordToTranslate.setText(practiceWord.getEnglish()); wordToTranslate.setText(answer.getEnglish());
} }
} }
@ -86,7 +86,7 @@ public class TranslationController extends Question {
usersInput.add(translationBox.getText()); usersInput.add(translationBox.getText());
ArrayList<DictionaryEntry> correctTranslation = new ArrayList<>(); ArrayList<DictionaryEntry> correctTranslation = new ArrayList<>();
correctTranslation.add(practiceList.get(chosenWord)); correctTranslation.add(answer);
checkAnswer(correctTranslation, usersInput, AssessmentGenerator.isEnglish); checkAnswer(correctTranslation, usersInput, AssessmentGenerator.isEnglish);

View file

@ -5,9 +5,13 @@ import uk.ac.aber.cs22120.group20.json.DictionaryEntry;
import java.util.LinkedList; import java.util.LinkedList;
public class TranslationQuestion extends Question { public class TranslationQuestion extends Question {
DictionaryEntry correctAnswer; private DictionaryEntry correctAnswer;
public TranslationQuestion(DictionaryEntry correctAnswer){ public TranslationQuestion(DictionaryEntry correctAnswer){
this.correctAnswer = correctAnswer; this.correctAnswer = correctAnswer;
} }
public DictionaryEntry getCorrectAnswer() {
return correctAnswer;
}
} }

View file

@ -23,17 +23,17 @@
<Font name="System Bold" size="25.0"/> <Font name="System Bold" size="25.0"/>
</font> </font>
</Label> </Label>
<Text fx:id="possibleAnswer1" layoutX="61.0" layoutY="176.0" onMouseClicked="#temp" strokeType="OUTSIDE" <Text fx:id="possibleAnswer1" layoutX="61.0" layoutY="176.0" onMouseClicked="#answer1" strokeType="OUTSIDE"
strokeWidth="0.0" text="English Word 1"/> strokeWidth="0.0" text="English Word 1"/>
<Text fx:id="possibleAnswer2" layoutX="260.0" layoutY="175.0" onMouseClicked="#temp" <Text fx:id="possibleAnswer2" layoutX="260.0" layoutY="175.0" onMouseClicked="#answer2"
strokeType="OUTSIDE" strokeWidth="0.0" text="English Word 2"/> strokeType="OUTSIDE" strokeWidth="0.0" text="English Word 2"/>
<Text fx:id="possibleAnswer3" layoutX="472.0" layoutY="175.0" onMouseClicked="#temp" <Text fx:id="possibleAnswer3" layoutX="472.0" layoutY="175.0" onMouseClicked="#answer3"
strokeType="OUTSIDE" strokeWidth="0.0" text="English Word 3"/> strokeType="OUTSIDE" strokeWidth="0.0" text="English Word 3"/>
<Text fx:id="possibleAnswer4" layoutX="61.0" layoutY="297.0" onMouseClicked="#temp" strokeType="OUTSIDE" <Text fx:id="possibleAnswer4" layoutX="61.0" layoutY="297.0" onMouseClicked="#answer4" strokeType="OUTSIDE"
strokeWidth="0.0" text="English Word 4"/> strokeWidth="0.0" text="English Word 4"/>
<Text fx:id="possibleAnswer5" layoutX="260.0" layoutY="297.0" onMouseClicked="#temp" <Text fx:id="possibleAnswer5" layoutX="260.0" layoutY="297.0" onMouseClicked="#answer5"
strokeType="OUTSIDE" strokeWidth="0.0" text="English Word 5"/> strokeType="OUTSIDE" strokeWidth="0.0" text="English Word 5"/>
<Text fx:id="possibleAnswer6" layoutX="472.0" layoutY="297.0" onMouseClicked="#temp" <Text fx:id="possibleAnswer6" layoutX="472.0" layoutY="297.0" onMouseClicked="#answer6"
strokeType="OUTSIDE" strokeWidth="0.0" text="English Word 6"/> strokeType="OUTSIDE" strokeWidth="0.0" text="English Word 6"/>
</children> </children>
</AnchorPane> </AnchorPane>