Filled psvm method finished console vocab program

This commit is contained in:
Artem Didytschuk 2020-10-08 22:02:40 +02:00
parent 6320c9daa9
commit 8e3f75d9cc
4 changed files with 139 additions and 17 deletions

View File

@ -0,0 +1,23 @@
package de.artem.main;
public class Main {
public Main(){
}
public static void main(String[] args) {
User user = new User(4);
user.addMultipleVocabs();
user.askIfDeToEng();
while(!user.allBoxesEmpty()){
user.setNextFullBox();
if(user.getDeToEng()){
user.doVocabsGerToEng();
} else {
user.doVocabsEngToGer();
}
}
System.out.println("Du hast alle Vokabeln gemacht!");
}
}

View File

@ -4,10 +4,10 @@ package de.artem.main;
import java.util.Scanner;
public class User {
private final VocabBox[] boxes;
private final int boxAmount;
private VocabBox[] boxes;
private int boxAmount;
private int currentBox;
private boolean deToEng;
/**
* @param pBoxAmount Gibt an wie viele Boxen der Vokabeltrainer haben soll.
*/
@ -20,9 +20,9 @@ public class User {
currentBox = 0;
}
public static void main(String[] args) {
}
/**
* @param pBox Gibt die Nummer der Box von 1 bis boxSize an.
@ -31,6 +31,7 @@ public class User {
currentBox = pBox;
}
public void addVocab(String pGerman, String pEnglish, int pBox) {
boxes[pBox].addVocabulary(pGerman, pEnglish);
}
@ -39,6 +40,25 @@ public class User {
boxes[0].addVocabulary(pGerman, pEnglish);
}
/**
* Funktion fragt in der Konsole nach Vokaben, die hinzugefügt werden müssen.
* Mindestens 1 Vokabel wird hinzugefügt. Danach wird gefragt ob mehr hinzugefügt werden sollen.
* Falls nein, wird die Methode beendet, falls ja wird die schleife nochmal durchlaufen.
*/
public void addMultipleVocabs(){
while(true) {
System.out.println("Schreibe zunächst die deutsche Vokabel, dann die Englische.");
String ger = typeAwnser();
String eng = typeAwnser();
addVocab(ger, eng);
System.out.println("Willst du noch eine Vokabel hinzufügen? j oder n");
ger = typeAwnser();
if(!ger.equalsIgnoreCase("j")){
return;
}
}
}
/**
* Sucht die Vokabel aus dem Spiel und entfernt sie.
*
@ -57,29 +77,42 @@ public class User {
*
* @return gibt den in die Konsole eingegebenen String zurück.
*/
private String typeAwnser() {
String typeAwnser() {
Scanner console = new Scanner(System.in);
return console.nextLine();
}
public void doVocabsGerToEng(){
boxes[currentBox].getVocabsList().toFirst();
System.out.println("Übersetze das Wort:"+boxes[currentBox].getGerman());
System.out.println("Tippe die Übersetzung!");
String awnser = typeAwnser();
if(testAwnser(awnser,"English")){
if(currentBox<boxes.length){
if(testAwnser(awnser,"Englisch")){
if(currentBox<boxes.length-1){
boxes[currentBox+1].getVocabsList().append(boxes[currentBox].getVocabsList().getContent());
}
boxes[currentBox].getVocabsList().remove();
System.out.println("Die Awntwort ist Richtig!");
System.out.println("Willst du deine Box ändern?: j oder n?");
String jn=typeAwnser();
if(jn.equalsIgnoreCase(j)){
System.out.println("Tippe die Box ein.");
jn = typeAwnser();
chooseBox(Integer.parseInt(jn));
//TODO: Zuende machen und Safety einbauen
} else {
System.out.println("Die Antwort ist Falsch! Versuche es nochmal");
doVocabsGerToEng();
}
}
public void doVocabsEngToGer(){
boxes[currentBox].getVocabsList().toFirst();
System.out.println("Übersetze das Wort:"+boxes[currentBox].getEnglish());
System.out.println("Tippe die Übersetzung!");
String awnser = typeAwnser();
if(testAwnser(awnser,"Deutsch")){
if(currentBox<boxes.length-1){
boxes[currentBox+1].getVocabsList().append(boxes[currentBox].getVocabsList().getContent());
}
boxes[currentBox].getVocabsList().remove();
System.out.println("Die Awntwort ist Richtig!");
} else {
System.out.println("Die Antwort ist Falsch! Versuche es nochmal");
doVocabsGerToEng();
}
}
@ -94,13 +127,79 @@ public class User {
public boolean testAwnser(String pAwnser, String testedLanguage) {
String lang;
if (testedLanguage.equalsIgnoreCase("Englisch")) {
lang = boxes[currentBox].getGerman();
} else if (testedLanguage.equalsIgnoreCase("Deutsch")) {
lang = boxes[currentBox].getEnglish();
} else if (testedLanguage.equalsIgnoreCase("Deutsch")) {
lang = boxes[currentBox].getGerman();
} else {
System.out.println("Error:Nicht unterstützte Sprache ausgewählt, testAwnser()");
return false;
}
return pAwnser.equals(lang);
}
/**
* Fragt ob von englisch zu deutsch oder deutsch zu englisch abgefragt werden soll.
*/
public void askIfDeToEng(){
System.out.println("Willst du von englisch zu deutsch oder von deutsch zu englisch lernen?");
System.out.println("Tippe j wenn du von deutsch zu Englisch lernen willst und n wenn anders herrum.");
String a = typeAwnser();
deToEng = a.equalsIgnoreCase("j");
}
/**
* Setzt currentBox auf die Box mit der tiefsten Nummer, welche nicht leer ist.
*/
public void setNextFullBox(){
if(!boxes[0].getVocabsList().isEmpty()){
currentBox=0;
}
if(!boxes[1].getVocabsList().isEmpty()){
currentBox=1;
}
if(!boxes[2].getVocabsList().isEmpty()){
currentBox=2;
}
if(!boxes[3].getVocabsList().isEmpty()){
currentBox=3;
}
}
public boolean getDeToEng(){
return deToEng;
}
public void askForBoxChange(){
System.out.println("Welche Box wählst du? Wähle zwischen 1 und 4.");
int i = Integer.parseInt(typeAwnser());
i-=1;
if(i>3 || i<0){
System.out.println("Die Box existiert nicht. Bitte wähle eine Box zwischen 1 und 4.");
askForBoxChange();
return;
}
if(boxes[i].getVocabsList().isEmpty()){
System.out.println("Die Box ist leer. Bitte Suche eine andere aus.");
askForBoxChange();
} else {
currentBox=i;
}
}
/**
* Liefert den Wert true zurück wenn alle Boxen leer sind.
* @return
* wenn alle Boxen leer sind true, sonst false.
*/
public boolean allBoxesEmpty(){
boolean a = boxes[0].getVocabsList().isEmpty();
boolean b = boxes[1].getVocabsList().isEmpty();
boolean c = boxes[2].getVocabsList().isEmpty();
boolean d = boxes[3].getVocabsList().isEmpty();
return a && b && c && d;
}
}