Christian Baltzer
5 years ago
12 changed files with 406 additions and 3 deletions
-
0Data.txt
-
BINsrc/main/java/com/.DS_Store
-
BINsrc/main/java/com/ugsbo/.DS_Store
-
33src/main/java/com/ugsbo/VokableKartenSchreiber/VokabelKartenSchreiber.java
-
91src/main/java/com/ugsbo/VokableKartenSchreiber/Vokabelkarte.java
-
67src/main/java/com/ugsbo/VokableKartenSchreiber/VokabelnwithTerminal.java
-
5src/main/java/com/ugsbo/gui/BasicGuiController.java
-
6src/main/java/com/ugsbo/gui/MainApp.java
-
2src/main/resources/com/ugsbo/gui/BasicGui.fxml
-
35src/main/resources/com/ugsbo/gui/Voabelkartenschreiber.fxml
-
62src/test/java/com/ugsbo/VokabelKartenSchreiber/NichtLeeralsohinzufügenTest.java
-
108src/test/java/com/ugsbo/VokabelKartenSchreiber/makeStringTest.java
@ -0,0 +1,33 @@ |
|||||
|
package com.ugsbo.VokableKartenSchreiber; |
||||
|
|
||||
|
import javafx.fxml.FXML; |
||||
|
import javafx.scene.control.*; |
||||
|
|
||||
|
|
||||
|
class VokabelKartenSchreiber{ |
||||
|
|
||||
|
@FXML |
||||
|
private static TextField Text_Name, Text_Frage, Text_Antwort1, Text_Antwort2, Text_Antwort3, Text_Antwort4; |
||||
|
|
||||
|
|
||||
|
public static void main(String[] args) { |
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
public static void button_absenden_pressed(){ |
||||
|
Vokabelkarte temp = new Vokabelkarte(); |
||||
|
|
||||
|
temp.makeString(Text_Name.getText(), Text_Frage.getText(), Text_Antwort1.getText(), Text_Antwort2.getText(), Text_Antwort3.getText(), Text_Antwort4.getText()); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
/*** |
||||
|
* Falls die Gui nicht ganz funktioniert, hier eine Version die per Terminal gesteuert wird |
||||
|
*/ |
||||
|
|
||||
|
public static void TerminalVersion() { |
||||
|
VokabelnwithTerminal.start(); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,91 @@ |
|||||
|
package com.ugsbo.VokableKartenSchreiber; |
||||
|
|
||||
|
import java.io.BufferedWriter; |
||||
|
import java.io.FileWriter; |
||||
|
import java.util.Scanner; |
||||
|
|
||||
|
public class Vokabelkarte{ |
||||
|
String Name; |
||||
|
String Frage; |
||||
|
String Antwort1; |
||||
|
String Antwort2; |
||||
|
String Antwort3; |
||||
|
String Antwort4; |
||||
|
|
||||
|
String Ergebnis; |
||||
|
|
||||
|
Scanner sc; |
||||
|
BufferedWriter bw; |
||||
|
|
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* @param sc |
||||
|
* @param bw |
||||
|
*/ |
||||
|
public Vokabelkarte() { |
||||
|
this.sc = new Scanner(System.in); |
||||
|
|
||||
|
try { |
||||
|
this.bw = new BufferedWriter(new FileWriter("Data.txt", true)); |
||||
|
} catch (Exception e) { |
||||
|
System.out.println("ne, wir nichts"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/*** |
||||
|
* |
||||
|
* @param Zwischenwert fügt ein Zwischenstück zwischen den beiden Strings ein |
||||
|
* @param neuesWort Der zu prüfende String |
||||
|
* @param bisherigerString Der String an den angehängt werden soll |
||||
|
* @return Der fertige String |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
//------------------------------------------------- |
||||
|
//Private |
||||
|
public String NichtLeeralsohinzufügen(String bisherigerString, String neuesWort, String Zwischenwert) { |
||||
|
if (!neuesWort.equals("")) { |
||||
|
neuesWort += Zwischenwert; |
||||
|
} |
||||
|
bisherigerString += neuesWort; |
||||
|
return bisherigerString; |
||||
|
} |
||||
|
|
||||
|
//------------------------------------------------- |
||||
|
//Public |
||||
|
|
||||
|
/*** |
||||
|
* Schreibt den Ergebnis String in eine Datei |
||||
|
*/ |
||||
|
public void schreiben() { |
||||
|
String Text = this.Ergebnis; |
||||
|
System.out.println(Text); |
||||
|
try { |
||||
|
bw.write(Text); |
||||
|
bw.write("\n"); |
||||
|
bw.flush(); |
||||
|
} catch (Exception e) { |
||||
|
System.out.println("AHHHHHHHHH"); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
/*** |
||||
|
* Erstellt aus den Eingetragenen Feldern den endgüligen String im gültigen Format |
||||
|
* Muster: Name/Frage/Antwort;Antwort |
||||
|
* @return gibt den formatierten String zurück |
||||
|
*/ |
||||
|
public String makeString(String Name,String Frage,String Antwort1,String Antwort2,String Antwort3,String Antwort4) { |
||||
|
String Ergebnis = ""; |
||||
|
Ergebnis = NichtLeeralsohinzufügen(Ergebnis, Name, "/"); |
||||
|
Ergebnis = NichtLeeralsohinzufügen(Ergebnis, Frage, "/"); |
||||
|
Ergebnis = NichtLeeralsohinzufügen(Ergebnis, Antwort1, ";"); |
||||
|
Ergebnis = NichtLeeralsohinzufügen(Ergebnis, Antwort2, ";"); |
||||
|
Ergebnis = NichtLeeralsohinzufügen(Ergebnis, Antwort3, ";"); |
||||
|
Ergebnis = NichtLeeralsohinzufügen(Ergebnis, Antwort4, ""); |
||||
|
this.Ergebnis = Ergebnis; |
||||
|
return Ergebnis; |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,67 @@ |
|||||
|
package com.ugsbo.VokableKartenSchreiber; |
||||
|
|
||||
|
import java.io.*; |
||||
|
import java.util.Scanner; |
||||
|
|
||||
|
public class VokabelnwithTerminal{ |
||||
|
|
||||
|
public static Scanner sc = new Scanner(System.in); |
||||
|
public static BufferedWriter bw; |
||||
|
|
||||
|
//Liest die Daten von der Tastatur ein und gibt Sie weiter |
||||
|
public static void start() { |
||||
|
System.out.println("Willkommen!\nBitte trage deine Karten in der Form Name, Frage, Antwort 1 und Antwort 2 ein. \nGibt es keine zweite Antwort, so lassen Sie das Feld frei."); |
||||
|
|
||||
|
try { |
||||
|
bw = new BufferedWriter(new FileWriter("Data.txt", true)); |
||||
|
} catch (Exception e) { |
||||
|
System.out.println("ne, wir nichts"); |
||||
|
} |
||||
|
|
||||
|
while (true){ |
||||
|
String Temp_String = ""; |
||||
|
System.out.println("---------------------------------------------------------------"); |
||||
|
System.out.println("Name?"); |
||||
|
String Name = sc.nextLine(); |
||||
|
if(!Name.isEmpty()){ |
||||
|
Temp_String += Name; |
||||
|
Temp_String += "/"; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
System.out.println("Frage?"); |
||||
|
Temp_String += sc.nextLine(); |
||||
|
Temp_String += "/"; |
||||
|
|
||||
|
|
||||
|
System.out.println("Antwort?"); |
||||
|
String Antwort = ""; |
||||
|
Temp_String += sc.nextLine(); |
||||
|
|
||||
|
while(true){ |
||||
|
System.out.println("nächste Antwort"); |
||||
|
Antwort = sc.nextLine(); |
||||
|
if (Antwort.isEmpty()){ |
||||
|
break; |
||||
|
} |
||||
|
Temp_String += ";" + Antwort; |
||||
|
} |
||||
|
Speichern(Temp_String); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// Schreibt den übergebenen String in die Datei |
||||
|
|
||||
|
public static void Speichern(String Text) { |
||||
|
|
||||
|
System.out.println(Text); |
||||
|
try { |
||||
|
bw.write(Text); |
||||
|
bw.write("\n"); |
||||
|
bw.flush(); |
||||
|
} catch (Exception e) { |
||||
|
System.out.println("AHHHHHHHHH"); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
@ -0,0 +1,35 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
|
||||
|
<?import javafx.scene.control.Button?> |
||||
|
<?import javafx.scene.control.Label?> |
||||
|
<?import javafx.scene.control.Menu?> |
||||
|
<?import javafx.scene.control.MenuBar?> |
||||
|
<?import javafx.scene.control.TextField?> |
||||
|
<?import javafx.scene.layout.AnchorPane?> |
||||
|
<?import javafx.scene.layout.VBox?> |
||||
|
|
||||
|
<VBox prefHeight="400.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.ugsbo.gui.Vokabelkartenschreiber"> |
||||
|
<children> |
||||
|
<MenuBar VBox.vgrow="NEVER"> |
||||
|
<menus> |
||||
|
<Menu mnemonicParsing="false" text="File"> |
||||
|
<graphic> |
||||
|
<Button mnemonicParsing="false" text="zurück" /> |
||||
|
</graphic> |
||||
|
</Menu> |
||||
|
</menus> |
||||
|
</MenuBar> |
||||
|
<AnchorPane maxHeight="-1.0" maxWidth="-1.0" prefHeight="-1.0" prefWidth="-1.0" VBox.vgrow="ALWAYS"> |
||||
|
<children> |
||||
|
<Label layoutX="14.0" layoutY="14.0" prefHeight="54.0" prefWidth="597.0" text="Willkommen! Bitte trage deine Karten in der unten gezeigte Form ein. Gibt es keine zweite Antwort, so lassen Sie das Feld frei. " /> |
||||
|
<TextField fx:id="Text_Name" layoutX="14.0" layoutY="84.0" prefHeight="27.0" prefWidth="597.0" promptText="Name" /> |
||||
|
<TextField fx:id="Text_Frage" layoutX="14.0" layoutY="123.0" prefHeight="27.0" prefWidth="597.0" promptText="Frage" /> |
||||
|
<TextField fx:id="Text_Antwort1" layoutX="14.0" layoutY="164.0" prefHeight="27.0" prefWidth="597.0" promptText="Antwort 1" /> |
||||
|
<TextField fx:id="Text_Antwort2" layoutX="14.0" layoutY="200.0" prefHeight="27.0" prefWidth="597.0" promptText="Antwort 2" /> |
||||
|
<TextField fx:id="Text_Antwort3" layoutX="14.0" layoutY="236.0" prefHeight="27.0" prefWidth="597.0" promptText="Antwort 3" /> |
||||
|
<TextField fx:id="Text_Antwort4" layoutX="14.0" layoutY="275.0" prefHeight="27.0" prefWidth="597.0" promptText="Antwort 4" /> |
||||
|
<Button fx:id="button_absenden" layoutX="277.0" layoutY="319.0" mnemonicParsing="false" onAction="#button_absenden_pressed" text="absenden" /> |
||||
|
</children> |
||||
|
</AnchorPane> |
||||
|
</children> |
||||
|
</VBox> |
@ -0,0 +1,62 @@ |
|||||
|
package com.ugsbo.VokabelKartenSchreiber; |
||||
|
|
||||
|
import static org.junit.Assert.assertEquals; |
||||
|
|
||||
|
import org.junit.Before; |
||||
|
import org.junit.Test; |
||||
|
|
||||
|
import com.ugsbo.VokableKartenSchreiber.Vokabelkarte; |
||||
|
|
||||
|
public class NichtLeeralsohinzufügenTest { |
||||
|
|
||||
|
private Vokabelkarte workingObjekt; |
||||
|
|
||||
|
|
||||
|
@Before |
||||
|
public void setup() { |
||||
|
workingObjekt = new Vokabelkarte(); |
||||
|
} |
||||
|
|
||||
|
@Test |
||||
|
public void NichtAlsLeeralsoHinzufügen_TestMitAllenParametern() { |
||||
|
Vokabelkarte WorkingObjekt = workingObjekt; |
||||
|
|
||||
|
String neuesWort = "prüfenTest"; |
||||
|
String wortfolgeBisher = "RückgabeTest"; |
||||
|
String separator = "ZwischenwertTest"; |
||||
|
String erwartet = "RückgabeTestprüfenTestZwischenwertTest"; |
||||
|
|
||||
|
String ergebnis = WorkingObjekt.NichtLeeralsohinzufügen(wortfolgeBisher,neuesWort,separator); |
||||
|
|
||||
|
assertEquals("Seperator angehängt + Neues Wort", erwartet, ergebnis); |
||||
|
} |
||||
|
|
||||
|
@Test |
||||
|
public void NichtAlsLeeralsoHinzufügen_neuesWortIstLeer() { |
||||
|
Vokabelkarte WorkingObjekt = workingObjekt; |
||||
|
|
||||
|
String neuesWort = ""; |
||||
|
String wortfolgeBisher = "RückgabeTest"; |
||||
|
String separator = "ZwischenwertTest"; |
||||
|
String erwartet = "RückgabeTest"; |
||||
|
|
||||
|
String ergebnis = WorkingObjekt.NichtLeeralsohinzufügen(wortfolgeBisher,neuesWort,separator); |
||||
|
|
||||
|
assertEquals("WortFolgebisher zurückgegeben", erwartet, ergebnis); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
@Test |
||||
|
public void NichtAlsLeeralsoHinzufügen_AllesLeer() { |
||||
|
Vokabelkarte WorkingObjekt = workingObjekt; |
||||
|
|
||||
|
String neuesWort = ""; |
||||
|
String wortfolgeBisher = ""; |
||||
|
String separator = ""; |
||||
|
String erwartet = ""; |
||||
|
|
||||
|
String ergebnis = WorkingObjekt.NichtLeeralsohinzufügen(wortfolgeBisher,neuesWort,separator); |
||||
|
|
||||
|
assertEquals("leer", erwartet, ergebnis); |
||||
|
} |
||||
|
} |
@ -0,0 +1,108 @@ |
|||||
|
package com.ugsbo.VokabelKartenSchreiber; |
||||
|
|
||||
|
import static org.junit.Assert.*; |
||||
|
|
||||
|
import org.junit.*; |
||||
|
|
||||
|
import com.ugsbo.VokableKartenSchreiber.Vokabelkarte; |
||||
|
|
||||
|
public class makeStringTest { |
||||
|
|
||||
|
private Vokabelkarte workingObjekt; |
||||
|
|
||||
|
@Before |
||||
|
public void setup() { |
||||
|
workingObjekt = new Vokabelkarte(); |
||||
|
} |
||||
|
|
||||
|
@Test |
||||
|
public void makeString_ReturnsStringKorrekt() { |
||||
|
Vokabelkarte WorkingObjekt = workingObjekt; |
||||
|
|
||||
|
String name = "TestName"; |
||||
|
String frage = "TestFrage"; |
||||
|
String antwort1 = "TestAntwort"; |
||||
|
String antwort2 = "TestAntwort"; |
||||
|
String antwort3 = "TestAntwort"; |
||||
|
String antwort4 = "TestAntwort"; |
||||
|
|
||||
|
String Erwartet = "TestName/TestFrage/TestAntwort;TestAntwort;TestAntwort;TestAntwort"; |
||||
|
|
||||
|
String Ergebnis = WorkingObjekt.makeString(name,frage,antwort1,antwort2,antwort3,antwort4); |
||||
|
|
||||
|
assertEquals("Name Frage und alle Antworten" , Erwartet, Ergebnis); |
||||
|
} |
||||
|
|
||||
|
public void makeString_ohneName() { |
||||
|
Vokabelkarte WorkingObjekt = workingObjekt; |
||||
|
|
||||
|
String name = ""; |
||||
|
String frage = "TestFrage"; |
||||
|
String antwort1 = "TestAntwort"; |
||||
|
String antwort2 = "TestAntwort"; |
||||
|
String antwort3 = "TestAntwort"; |
||||
|
String antwort4 = "TestAntwort"; |
||||
|
|
||||
|
String Erwartet = "TestFrage/TestAntwort;TestAntwort;TestAntwort;TestAntwort"; |
||||
|
|
||||
|
String Ergebnis = WorkingObjekt.makeString(name,frage,antwort1,antwort2,antwort3,antwort4); |
||||
|
|
||||
|
assertEquals("Frage und alle Antworten" , Erwartet, Ergebnis); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Test |
||||
|
public void makeStringReturnsStringNichtKorrekt() { |
||||
|
Vokabelkarte WorkingObjekt = workingObjekt; |
||||
|
|
||||
|
String name = "TestName"; |
||||
|
String frage = ""; |
||||
|
String antwort1 = ""; |
||||
|
String antwort2 = ""; |
||||
|
String antwort3 = "TestAntwort"; |
||||
|
String antwort4 = "TestAntwort"; |
||||
|
|
||||
|
String Erwartet = "TestName/TestAntwort;TestAntwort"; |
||||
|
|
||||
|
String Ergebnis = WorkingObjekt.makeString(name,frage,antwort1,antwort2,antwort3,antwort4); |
||||
|
|
||||
|
assertEquals("Name und drei Antworten" , Erwartet, Ergebnis); |
||||
|
} |
||||
|
|
||||
|
@Test |
||||
|
public void makeStringReturns_Leer() { |
||||
|
Vokabelkarte WorkingObjekt = workingObjekt; |
||||
|
|
||||
|
String name = ""; |
||||
|
String frage = ""; |
||||
|
String antwort1 = ""; |
||||
|
String antwort2 = ""; |
||||
|
String antwort3 = ""; |
||||
|
String antwort4 = ""; |
||||
|
|
||||
|
String Erwartet = ""; |
||||
|
|
||||
|
String Ergebnis = WorkingObjekt.makeString(name,frage,antwort1,antwort2,antwort3,antwort4); |
||||
|
|
||||
|
assertEquals("leer" , Erwartet, Ergebnis); |
||||
|
} |
||||
|
|
||||
|
@Test |
||||
|
public void makeStringReturnsStringUnvolständigKeineFrage() { |
||||
|
Vokabelkarte WorkingObjekt = workingObjekt; |
||||
|
|
||||
|
|
||||
|
String name = "TestName"; |
||||
|
String frage = ""; |
||||
|
String antwort1 = "TestAntwort"; |
||||
|
String antwort2 = "TestAntwort"; |
||||
|
String antwort3 = "TestAntwort"; |
||||
|
String antwort4 = "TestAntwort"; |
||||
|
|
||||
|
String Erwartet = "TestName/TestAntwort;TestAntwort;TestAntwort;TestAntwort"; |
||||
|
|
||||
|
String Ergebnis = WorkingObjekt.makeString(name,frage,antwort1,antwort2,antwort3,antwort4); |
||||
|
|
||||
|
assertEquals("Name und alle Antworten" , Erwartet, Ergebnis); |
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue