This commit is contained in:
osp1 2020-04-27 19:05:53 +01:00
commit 4e1bb05b79
4 changed files with 70 additions and 22 deletions

View file

View file

@ -0,0 +1,48 @@
package uk.ac.aber.cs22120.group20.selfassessment;
import uk.ac.aber.cs22120.group20.json.DictionaryEntry;
import java.util.ArrayList;
/**
* Abstract class contains the basic information that all the shared information between the
* types of test questions including the questions correct answers and possible answers. All question
* classes will extend this class.
* @Author
* @Version
* @See
*/
public class Question {
public int correctAnswer = 0;
public int wrongAnswer =0;
/**
* Constructor for
* WordEnterQuestion that takes a WelshDictionary object that is being tested on as the parameter.
* @param correctAnswer
*/
public void wordEnterQuestion(DictionaryEntry correctAnswer){
}
public void checkAnswer(ArrayList<DictionaryEntry> listOfCorrectQuestions, ArrayList<String>listOfAnswers, boolean isEnglish){
if(isEnglish){
for(int i=0; i<listOfCorrectQuestions.size();i++){
if(listOfCorrectQuestions.get(i).getEnglish().equals(listOfAnswers.get(i))){
correctAnswer++;
}else wrongAnswer++;
}
}else{
for(int i=0; i<listOfCorrectQuestions.size();i++){
if(listOfCorrectQuestions.get(i).getWelsh().equals(listOfAnswers.get(i))){
correctAnswer++;
}else wrongAnswer++;
}
}
}
}

@ -0,0 +1 @@
Subproject commit c46b21b0a548aeac2d83e1dee0bd662d93f07dfb

View file

@ -9,6 +9,10 @@ import javafx.scene.text.Text;
import java.util.ArrayList;
import java.util.Random;
import uk.ac.aber.cs22120.group20.json.DictionaryEntry;
import uk.ac.aber.cs22120.group20.javafx.Application;
/**
* Controller for the translationTest fxml file.
@ -17,7 +21,7 @@ import java.util.Random;
* @version 0.9
*
*/
public class TranslationController {
public class TranslationController extends Question {
ArrayList<DictionaryEntry> practiceList = new ArrayList<>();
@ -66,7 +70,7 @@ public class TranslationController {
submitButton.setImage(new Image ("file:src/main/resources/assets/right-icon.png"));
for(DictionaryEntry entry : App.dictionary){
for(DictionaryEntry entry : Application.dictionary){
if(entry.isPracticeWord()){
practiceList.add(entry);
}
@ -82,10 +86,10 @@ public class TranslationController {
incorrectGuesses.setText("Incorrect Guesses: 0");
if(englishOrWelsh){
wordToTranslate.setText(practiceList.get(chosenWord).getEnglish());
wordToTranslate.setText(practiceList.get(chosenWord).getWelsh());
}
else{
wordToTranslate.setText(practiceList.get(chosenWord).getWelsh());
wordToTranslate.setText(practiceList.get(chosenWord).getEnglish());
}
}
@ -99,25 +103,20 @@ public class TranslationController {
@FXML
void translateWord() {
ArrayList<String> usersInput = new ArrayList<>();
usersInput.add(translationBox.getText());
if(englishOrWelsh) {
if (translationBox.getText().equals(practiceList.get(chosenWord).getWelsh())) {
correctGuessesInt++;
} else {
incorrectGuessesInt++;
}
}
else{
if (translationBox.getText().equals(practiceList.get(chosenWord).getEnglish())) {
correctGuessesInt++;
} else {
incorrectGuessesInt++;
}
}
ArrayList<DictionaryEntry> correctTranslation = new ArrayList<>();
correctTranslation.add(practiceList.get(chosenWord));
checkAnswer(correctTranslation, usersInput, englishOrWelsh);
correctGuesses.setText("Correct Guesses: " + correctGuessesInt);
incorrectGuesses.setText("Incorrect Guesses: " + incorrectGuessesInt);
correctGuesses.setText("Correct Guesses: " + correctAnswer);
incorrectGuesses.setText("Incorrect Guesses: " + wrongAnswer);
@ -135,10 +134,10 @@ public class TranslationController {
}
if(englishOrWelsh){
wordToTranslate.setText(practiceList.get(chosenWord).getEnglish());
wordToTranslate.setText(practiceList.get(chosenWord).getWelsh());
}
else{
wordToTranslate.setText(practiceList.get(chosenWord).getWelsh());
wordToTranslate.setText(practiceList.get(chosenWord).getEnglish());
}
}
}