diff --git a/Data.txt b/Data.txt new file mode 100644 index 0000000..e69de29 diff --git a/pom.xml b/pom.xml index 35fb9b7..88b3b5b 100644 --- a/pom.xml +++ b/pom.xml @@ -24,6 +24,12 @@ 4.11 test + + org.hamcrest + hamcrest-junit + 2.0.0.0 + test + org.mockito @@ -41,6 +47,11 @@ javafx-fxml 12.0.1 + + com.google.code.gson + gson + 2.8.5 + @@ -99,7 +110,7 @@ 12 UGSBO launcher - UGSBO/com.ugsbo.gui.MainApp + UGSBO/com.ugsbo.gui.StartApplication diff --git a/src/main/java/com/.DS_Store b/src/main/java/com/.DS_Store new file mode 100644 index 0000000..2db24ad Binary files /dev/null and b/src/main/java/com/.DS_Store differ diff --git a/src/main/java/com/ugsbo/.DS_Store b/src/main/java/com/ugsbo/.DS_Store new file mode 100644 index 0000000..9f8ac73 Binary files /dev/null and b/src/main/java/com/ugsbo/.DS_Store differ diff --git a/src/main/java/com/ugsbo/Crypto/Crypto_Logic.java b/src/main/java/com/ugsbo/Crypto/Crypto_Logic.java new file mode 100644 index 0000000..62f1dda --- /dev/null +++ b/src/main/java/com/ugsbo/Crypto/Crypto_Logic.java @@ -0,0 +1,22 @@ +package com.ugsbo.Crypto; + +import java.io.UnsupportedEncodingException; +import java.security.GeneralSecurityException; + +public class Crypto_Logic { + + public static void main(String[] args) throws UnsupportedEncodingException, GeneralSecurityException { + // TODO Auto-generated method stub + String test = "Hallo, mein Name ist Christian"; + + Payload temp = new Payload(); + temp.setOffen(test); + temp.setPassword("geheim"); + temp.verschlüsseln(); + System.out.println(temp.getVerschlüsselt()); + + temp.entschlüsseln(); + System.out.println(temp.getOffen()); + } + +} diff --git a/src/main/java/com/ugsbo/Crypto/Payload.java b/src/main/java/com/ugsbo/Crypto/Payload.java new file mode 100644 index 0000000..a2bd031 --- /dev/null +++ b/src/main/java/com/ugsbo/Crypto/Payload.java @@ -0,0 +1,92 @@ +package com.ugsbo.Crypto; + +import java.io.UnsupportedEncodingException; +import java.security.GeneralSecurityException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Arrays; +import java.util.Base64; +import javax.crypto.*; +import javax.crypto.spec.SecretKeySpec; + + +public class Payload { + + String offen; + String verschlüsselt; + SecretKeySpec password; + + public Payload() { + offen = ""; + verschlüsselt = ""; + + try { + this.setPassword(""); + } catch (UnsupportedEncodingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (GeneralSecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + + public String getOffen() { + return offen; + } + + + + public String getVerschlüsselt() { + return verschlüsselt; + } + + public void setOffen(String offen) { + this.offen = offen; + } + + + + public void setVerschlüsselt(String verschlüsselt) { + this.verschlüsselt = verschlüsselt; + } + + + + public void setPassword(String password) + throws GeneralSecurityException, UnsupportedEncodingException { + byte[] key = (password).getBytes("UTF-8"); + + // aus dem Array einen Hash-Wert erzeugen mit MD5 oder SHA + MessageDigest sha = MessageDigest.getInstance("SHA-256"); + key = sha.digest(key); + + // nur die ersten 128 bit nutzen + key = Arrays.copyOf(key, 16); + + // der fertige Schluessel + this.password = new SecretKeySpec(key, "AES"); + } + + + + public void verschlüsseln() throws NoSuchAlgorithmException, GeneralSecurityException { + Cipher cipher = Cipher.getInstance("AES"); + cipher.init(Cipher.ENCRYPT_MODE, password); + byte[] encrypted = cipher.doFinal(offen.getBytes()); + + verschlüsselt = Base64.getEncoder().encodeToString(encrypted); + } + + public void entschlüsseln() throws NoSuchAlgorithmException, GeneralSecurityException { + byte[] text = Base64.getDecoder().decode(verschlüsselt); + + Cipher cipher = Cipher.getInstance("AES"); + cipher.init(Cipher.DECRYPT_MODE, password); + byte[] cipherData2 = cipher.doFinal(text); + offen = new String(cipherData2); + + } + +} diff --git a/src/main/java/com/ugsbo/FirewallOfDeath/GrundFunktion.java b/src/main/java/com/ugsbo/FirewallOfDeath/GrundFunktion.java new file mode 100644 index 0000000..ea9022f --- /dev/null +++ b/src/main/java/com/ugsbo/FirewallOfDeath/GrundFunktion.java @@ -0,0 +1,36 @@ +package com.ugsbo.FirewallOfDeath; + +import java.io.IOException; +import java.net.UnknownHostException; +import java.util.concurrent.TimeUnit; + +/*** + * In manchen Ländern gibt es keinen freien zugang zum Internett. Zum Glück gibt es VPN, diese haben aber die doofe Eigenschaft zusammenzubrechen. + * Praktischerweise sind in diesen Ländern meist alle Dienste von Google gesperrt, weswegen wir am Ping sehen können ob wir noch geschützt sind oder nicht. + * @author Christian + */ + +public class GrundFunktion { + + public static void main(String[] args) throws InterruptedException { + // TODO Auto-generated method stub + while (true) { + try { + if (NetzFunktion.pingTogoogle()) { + System.out.println("alles gut"); + + }else { + System.out.println("PRÜFE SOFORT DEINEN VPN!!!"); + } + TimeUnit.MINUTES.sleep(1); + } + catch (UnknownHostException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} +} diff --git a/src/main/java/com/ugsbo/FirewallOfDeath/NetzFunktion.java b/src/main/java/com/ugsbo/FirewallOfDeath/NetzFunktion.java new file mode 100644 index 0000000..748781d --- /dev/null +++ b/src/main/java/com/ugsbo/FirewallOfDeath/NetzFunktion.java @@ -0,0 +1,40 @@ +package com.ugsbo.FirewallOfDeath; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.UnknownHostException; + +class NetzFunktion { + + /*** + * sendet einen Ping an google + * @return boolean können wir google erreichen oder nicht? + * @throws IOException + * @throws UnknownHostException + */ + + public static boolean pingTogoogle() throws IOException,UnknownHostException { + //Googel IP adresse + try { + URL url = new URL("http://www.google.com"); + + //open a connection to that source + HttpURLConnection urlConnect = (HttpURLConnection)url.openConnection(); + + + //Gibt es keine Verbindung schlägt diese Zeile fehl. + @SuppressWarnings("unused") + Object objData = urlConnect.getContent(); + + }catch (Exception e) { + e.printStackTrace(); + return false; + } + return true; + + } + + + +} diff --git a/src/main/java/com/ugsbo/IsMyComputerOn/IsMyComputerOn_App.java b/src/main/java/com/ugsbo/IsMyComputerOn/IsMyComputerOn_App.java new file mode 100644 index 0000000..bc31fc3 --- /dev/null +++ b/src/main/java/com/ugsbo/IsMyComputerOn/IsMyComputerOn_App.java @@ -0,0 +1,29 @@ +package com.ugsbo.IsMyComputerOn; + +import java.util.concurrent.TimeUnit; + +public class IsMyComputerOn_App { + + public static void main(String[] args) { + while (true) { + System.out.print("Dein Rechner ist: "); + System.out.println((IstErAn()?"AN":"AUS")); + try { + TimeUnit.MINUTES.sleep(1); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + /*** + * + * @return true Da wir davon ausgehen, dass das Program nur ausgeführt werden kann wenn der Rechner läuft, geben wir immer true zurück. + */ + + public static boolean IstErAn() { + // TODO Auto-generated method stub + return true; + } +} diff --git a/src/main/java/com/ugsbo/VokableKartenSchreiber/VokabelKartenSchreiber.java b/src/main/java/com/ugsbo/VokableKartenSchreiber/VokabelKartenSchreiber.java new file mode 100644 index 0000000..27f95b5 --- /dev/null +++ b/src/main/java/com/ugsbo/VokableKartenSchreiber/VokabelKartenSchreiber.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(); + } + +} \ No newline at end of file diff --git a/src/main/java/com/ugsbo/VokableKartenSchreiber/Vokabelkarte.java b/src/main/java/com/ugsbo/VokableKartenSchreiber/Vokabelkarte.java new file mode 100644 index 0000000..99cc9e6 --- /dev/null +++ b/src/main/java/com/ugsbo/VokableKartenSchreiber/Vokabelkarte.java @@ -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; + } + +} \ No newline at end of file diff --git a/src/main/java/com/ugsbo/VokableKartenSchreiber/VokabelnwithTerminal.java b/src/main/java/com/ugsbo/VokableKartenSchreiber/VokabelnwithTerminal.java new file mode 100644 index 0000000..a0c87ab --- /dev/null +++ b/src/main/java/com/ugsbo/VokableKartenSchreiber/VokabelnwithTerminal.java @@ -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"); + } + + } +} \ No newline at end of file diff --git a/src/main/java/com/ugsbo/auslandssemester/AuslandssemesterMain.java b/src/main/java/com/ugsbo/auslandssemester/AuslandssemesterMain.java new file mode 100644 index 0000000..a8add0e --- /dev/null +++ b/src/main/java/com/ugsbo/auslandssemester/AuslandssemesterMain.java @@ -0,0 +1,45 @@ +package com.ugsbo.auslandssemester; + +import java.util.Scanner; + +public class AuslandssemesterMain { + + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner in = new Scanner(System.in); + System.out.println("Bitte gebe deinen Nachnamen ein."); + String name = in.nextLine(); + System.out.println("Bitte gebe deinen Vornamen ein."); + String vorname = in.nextLine(); + + System.out + .println("Bitte schreibe auf ob du nach Europa, Australien, Neuseeland, Asien oder in die USA gehst."); + String destination = in.nextLine(); + if (!(destination.equals("Europa")) && !(destination.equals("Australien")) && !(destination.equals("Neuseeland")) && !(destination.equals("Asien")) && !(destination.equals("USA")) ) { + System.out.println("Plaese Start Again. falsche Eingabe."); + } else { + System.out.println("Sage mir bitte in wie vielen Monaten du ins Ausland moechtest?"); + int inMonaten = in.nextInt(); + System.out.println("Danke"); + Sitzung g = new Sitzung(name, vorname, inMonaten, destination); + + System.out.println("Tipp 1:"); + System.out.println(g.deadline(g.kategorieInMonaten(), g.kategorieDestination())); + + System.out.println("Tipp 2:"); + System.out.println(g.finanzierung(g.kategorieInMonaten(), g.kategorieDestination())); + + + System.out.println("Tipp 4:"); + System.out.println(g.learningAgreement(g.kategorieInMonaten())); + + + System.out.println("Tipp 3:"); + System.out.println(g.wohnen(g.kategorieInMonaten())); + + System.out.println("Tipp 3:"); + System.out.println(g.packen(g.kategorieInMonaten())); + + } + } +} diff --git a/src/main/java/com/ugsbo/auslandssemester/Sitzung.java b/src/main/java/com/ugsbo/auslandssemester/Sitzung.java new file mode 100644 index 0000000..b4d8b26 --- /dev/null +++ b/src/main/java/com/ugsbo/auslandssemester/Sitzung.java @@ -0,0 +1,180 @@ +package com.ugsbo.auslandssemester; + +public class Sitzung { + private String name; + private String vorname; + private int inMonaten; + private String destination; + + // Konstruktor mit Übergabewerten + public Sitzung(String nachname, String vor, int monate, String ziel) { + this.name = nachname; + this.vorname = vor; + this.inMonaten = monate; + this.destination = ziel; + } + + public String kategorieDestination() { + String kategorie = "Europa"; + if (destination == "Australien" || destination == "Neuseeland" || destination == "Asien") { + kategorie = "Asien"; + } + if (destination == "USA") { + kategorie = "USA"; + } + return kategorie; + } + + public int kategorieInMonaten() { + int kategorie = 4; // alles was größer als 12 Monate ist + + if (inMonaten <= 2) { + kategorie = 1; + } + if (inMonaten > 2 && inMonaten <= 5) { + kategorie = 2; + } + if (inMonaten > 5 && inMonaten <= 12) { + kategorie = 3; + } + + return kategorie; + } + // tipps + + // tipp zum learning Agreement + + public String learningAgreement(int kategorieZeit) { + String tipp = "kein Tipp."; + if (kategorieZeit == 4 || kategorieZeit == 3) { + tipp = "Jetzt musst du dich noch nicht über das Learning Agreement informieren."; + } + + if (kategorieZeit == 2) { + tipp = "Jetzt solltest du dich über das Learning Agreement informieren. Was musst du wissen? Wer muss es unterzeichnen? Wo musst du es abgeben?"; + } + if (kategorieZeit == 1) { + tipp = "Wenn du jetzt noch kein Learning Agreement hast ist das seltsam. Frag so schnell es geht mal jemanden ob du eins brauchst."; + } + return tipp; + + } + + public String packen(int kategorieZeit) { + String tipp = "kein Tipp."; + if (kategorieZeit == 4 || kategorieZeit == 3) { + tipp = "Kein Stress. DU hast noch eine Ewigkeit Zeit zum packen."; + } + + if (kategorieZeit == 2) { + tipp = "Wenn du magst kannst schonmal anfangen eine Liste zu schreiben."; + } + if (kategorieZeit == 1) { + tipp = "Jetzt solltest du definitiv eine Liste schreiben und so langsam mal anfangen."; + } + return tipp; + + } + + // neuer Tipp zu den Deadlines + + public String deadline(int kategorieZeit, String kategorieZiel) { + String tipp = "kein Tipp"; + if (kategorieZiel == "USA" || kategorieZiel == "Asien") { + if (kategorieZeit == 4) { + tipp = "Zu diesem Zeitraum ist es sinnvoll sich über die entsprechenden Deadlines zu informieren."; + } + + if (kategorieZeit == 3) { + tipp = "Jetzt solltest du dich auf jeden Fall über die Deadlines informieren."; + } + + if (kategorieZeit == 2) { + tipp = "Die Bewerbungsdeadlines sind hier wahrscheinlich schon durch. Stipendien könnten aber noch gehen"; + } + if (kategorieZeit == 1) { + tipp = "Es tut mir Leid, aber du bist zu spät dran. Alle Deadlines sind durch."; + } + + } else { + if (kategorieZeit == 4) { + tipp = "Zu diesem Zeitpunkt musst du dich noch nicht um Deadlines sorgen. Mal schauen schadet aber nicht."; + } + + if (kategorieZeit == 3) { + tipp = "Jetzt wäre es wichtig sich über Deadlines zu informieren."; + } + + if (kategorieZeit == 2) { + tipp = "Jetzt aber wirklich zügig. Die Deadlines sind bestimmt noch nicht ganz abgelaufen."; + } + if (kategorieZeit == 1) { + tipp = "Es tut mir Leid, aber du bist zu spät dran. Alle Deadlines sind durch."; + } + } + return tipp; + + } + + //neuer Tipp zur Finanzierung + + public String finanzierung(int kategorieZeit, String kategorieZiel) { + String tipp = "kein Tipp"; + if(kategorieZiel == "USA" || kategorieZiel == "Asien") { + if(kategorieZeit == 4) { + tipp = "Finanzierung ist keine leichte Sache, darüber kann man sich nie zu früh Gedanken machen. Stichwort: Stipendium."; + } + + if(kategorieZeit == 3) { + tipp = "Jetzt musst du auf jeden Fall überlegen wie du das finanziern willst. Sprich vielleicht mal mit deinen Eltern oder such nach Stipendien"; + } + + if(kategorieZeit == 2) { + tipp = "Wenn du dich noch nicht um die Finanzierung gekümmert hast, dann musst du dich jetzt aber ran halten."; + } + if(kategorieZeit == 1) { + tipp = "Selbst wenn du bisher noch gar nicht an die Finanzierung gedacht hast solltest du es jetzt tun. Besser spät als nie."; + } + + } else { + if(kategorieZeit == 4) { + tipp = "Über die Finanzierung kann man sich nie zu früh Gedanken machen. Aber bitte keine Hektik."; + } + + if(kategorieZeit == 3) { + tipp = "Denk am besten schon mal ein bisschen an die Finanzierung. Frag an ob Erasmus für dich in Frage kommt."; + } + + if(kategorieZeit == 2) { + tipp = "Wenn du dich auf Ersamus beworben hast dann solltest du demnächst deine Rückmeldung bekommen."; + } + if(kategorieZeit == 1) { + tipp = "Wenn du ein Erasmus+ STipendium bekommst, dann wirst du noch einen Englischtest absolvieren und einen Vertrag unterschreiben müssen. Denk auch an deine Immatrikulationsbescheingung."; + } + } + return tipp; + + } + + // neuer Tipp zum Wohnen + public String wohnen(int kategorieZeit) { + String tipp = "kein Tipp."; + if (kategorieZeit == 4) { + tipp = "Schau dich am besten schon mal nach Wohnungen um. Manchmal gibt es Webseiten auf denen man über die Zeit Punkte sammelt."; + } + + if (kategorieZeit == 3) { + tipp = "Jetzt informier dich definitiv schon mal wie es mit Wohnen ist. Manchmal gibt es Webseiten auf denen man über die Zeit Punkte sammelt."; + } + + if (kategorieZeit == 2) { + tipp = "Jetzt wird es höchste Zeit nach einer Wohung zu schauen."; + } + if (kategorieZeit == 1) { + tipp = "Jetzt ist es schon fast zu spät um nach einer Wohnung zu suchen"; + } + return tipp; + + } + +} diff --git a/src/main/java/com/ugsbo/complexnumcalc/ComplexNumber.java b/src/main/java/com/ugsbo/complexnumcalc/ComplexNumber.java new file mode 100644 index 0000000..b05fea2 --- /dev/null +++ b/src/main/java/com/ugsbo/complexnumcalc/ComplexNumber.java @@ -0,0 +1,156 @@ +package com.ugsbo.complexnumcalc; + +public class ComplexNumber { + private Double realPart; + private Double imaginaryPart; + + /** + * @param realPart The real part of the complex Number + * @param imaginaryPart The imaginary part of the complex Number + */ + + public ComplexNumber(Double realPart, Double imaginaryPart) { + this.realPart = realPart; + this.imaginaryPart = imaginaryPart; + } + + /** + * @return the realPart + */ + public Double getRealPart() { + return realPart; + } + + /** + * @param realPart the realPart to set + */ + public void setRealPart(Double realPart) { + this.realPart = realPart; + } + + /** + * @return the imaginaryPart + */ + public Double getImaginaryPart() { + return imaginaryPart; + } + + /** + * @param imaginaryPart the imaginaryPart to set + */ + public void setImaginaryPart(Double imaginaryPart) { + this.imaginaryPart = imaginaryPart; + } + + /** + * Checks if the given complex Number is equal to this object. + * + * @param complexNumber The number wich gets compared with this Instance + * @return True if the complex Numbers are Equal + */ + @Override + public boolean equals(Object complexNumber) { + if (complexNumber instanceof ComplexNumber){ + ComplexNumber that = (ComplexNumber) complexNumber; + return this.realPart.equals(that.realPart) && this.imaginaryPart.equals(that.imaginaryPart); + } else { + return false; + } + } + + /** + * Adds two complex Numbers together. + * + * @param addend The complex Number. + * @return The result of adding the two complex Numbers together, as a conplex + * Number. + */ + public ComplexNumber add(ComplexNumber addend) { + Double sumRealPart, sumImaginaryPart; + + sumRealPart = this.realPart + addend.realPart; + sumImaginaryPart = this.imaginaryPart + addend.imaginaryPart; + + ComplexNumber sum = new ComplexNumber(sumRealPart, sumImaginaryPart); + + return sum; + } + + /** + * Substracts the Subtrahend form this instance. + * + * @param subtrahend The Number wich will be substracted form the Minuend + * @return The Differenz of the Minuend and Subtrahend. + */ + public ComplexNumber substract(ComplexNumber subtrahend) { + Double differenzRealPart, differenzImaginaryPart; + + differenzRealPart = this.realPart - subtrahend.realPart; + differenzImaginaryPart = this.imaginaryPart - subtrahend.imaginaryPart; + + ComplexNumber differenz = new ComplexNumber(differenzRealPart, differenzImaginaryPart); + + return differenz; + } + + /** + * Multiplies the faktor with this Instance. + * + * @param faktor The ComplexNumber by wich this Instance will get multiplyed + * @return The product of this Instance and the faktor + */ + public ComplexNumber multiply(ComplexNumber faktor) { + Double productRealPart, productImaginaryPart; + + productRealPart = this.realPart * faktor.realPart - this.imaginaryPart * faktor.imaginaryPart; + productImaginaryPart = this.realPart * faktor.imaginaryPart + this.imaginaryPart * faktor.realPart; + + ComplexNumber product = new ComplexNumber(productRealPart, productImaginaryPart); + + return product; + } + + /** + * Divides the dividend by the divisor, the dividend is this Instance. + * + * @param divisor The ComplexNumber by wich this Instance will get divided + * @return The Qoutient of the Instance and the divisor + */ + public ComplexNumber divide(ComplexNumber divisor) { + Double qoutientRealPart, qoutientImaginaryPart, tempDivisor; + + tempDivisor = divisor.realPart * divisor.realPart + divisor.imaginaryPart * divisor.imaginaryPart; + qoutientRealPart = this.realPart * divisor.realPart + this.imaginaryPart * divisor.imaginaryPart; + qoutientImaginaryPart = this.imaginaryPart * divisor.realPart - this.realPart * divisor.imaginaryPart; + qoutientImaginaryPart /= tempDivisor; + qoutientRealPart /= tempDivisor; + + ComplexNumber qoutient = new ComplexNumber(qoutientRealPart, qoutientImaginaryPart); + + return qoutient; + } + + /** + * Calucates the absolute value of this complex number + * @return the absolute value + */ + public Double absolutValueOf(){ + Double absoluteValue = Math.sqrt(Math.pow(this.realPart, 2) + Math.pow(this.imaginaryPart, 2)) ; + return absoluteValue; + } + + /** + * Calucates the absolute value of this complex number + * @return the absolute value + */ + public ComplexNumber conjugationOf(){ + if(this.imaginaryPart.equals(Double.valueOf(0))){ + return this; + } else { + this.imaginaryPart *= (-1); + return this; + } + + } + +} \ No newline at end of file diff --git a/src/main/java/com/ugsbo/entscheider/Entscheider.java b/src/main/java/com/ugsbo/entscheider/Entscheider.java new file mode 100644 index 0000000..8f2aebd --- /dev/null +++ b/src/main/java/com/ugsbo/entscheider/Entscheider.java @@ -0,0 +1,192 @@ + +/** + * + */ +package com.ugsbo.entscheider; + +import java.util.Scanner; +import java.util.*; + +/** + * @author bruec + * + */ +public class Entscheider { + + /** + * @param args + */ + public static void main(String[] args) { + System.out.println("Herzlich Willkommen!"); + String a = fragen(); + System.out.println(a); + if(a != "Na dann halt nicht. Tschüssi.") { + System.out.println("Auf Wiedersehen. Frag mich gerne nochmal wenn du mal wieder nicht weisst, ob du in die Vorlesung gehen solltest oder nicht."); + } + + } +//testbar + //Eingaben -> alter, lernen, gelb, apfel, mot, harry, fruehstueck, anzahl + public static String ergebnis(int alter, int lernen, int gelb, int apfel, int mot, int harry, int fruehstueck, int anzahl) { + int erg = (((alter + lernen + gelb) * apfel) / (mot + harry + fruehstueck)) - anzahl; + String hilfe = ""; + if (erg < 5) + hilfe = "Ich kann doch nicht fuer dich entscheiden, dass musst du schon selber wissen."; + if (erg >= 5 && erg < 15) + hilfe = "Naja, dann geh halt nach Hause und ruh dich aus."; + if (erg >= 15) + hilfe = "Jetzt wieder gehen? Dann bist du doch voellig umsonst aufgestanden. Geh einfach hin."; + + return hilfe; + } +//nicht testbar + public static String fragen() { + // Eingangsfrage + System.out.println( + "Du willst also wissen ob du in die Veranstaltung gehen sollst oder nicht? Gib 1 für Ja ein 0 für Nein."); + int a = getAnInteger(); + if (a == 1 || a == 0) { + if (a == 1) { + System.out.println("Dann werde ich dir jetzt ein paar Fragen stellen"); + } else { + return("Na dann halt nicht. Tschüssi."); + } + + } else { + a = pruefen(a); + if (a == 1) { + System.out.println("Dann werde ich dir jetzt ein paar Fragen stellen"); + } else { + return ("Na dann halt nicht. Tschüssi.") ; + } + + } + // zweite Frage + System.out.println("Wie alt bist du?"); + int alter = getAnInteger(); + if (alter > 0) { + System.out.println(alter); + } else { + while (alter <= 0) { + System.out.println("Versuches es nochmal. Du musst mindestens 1 sein."); + alter = getAnInteger(); + } + } + + // dritte Frage + System.out.println("Auf einer Skala von 1 bis 10 wie motiviert bist du?"); + int mot = getAnInteger(); + if (mot >= 1 && mot <= 10) { + System.out.println(mot); + } else { + mot = skalaTest(mot); + System.out.println(mot); + } + + // vierte Frage + System.out.println("Hast du gefrühstückt? Bei Ja bitte 1 und bei Nein bitte 0"); + int fruehstueck = getAnInteger(); + if (fruehstueck == 1 || fruehstueck == 0) { + System.out.println(fruehstueck); + } else { + fruehstueck = pruefen(fruehstueck); + System.out.println(fruehstueck); + } + + // fuenfte Frage + System.out.println("Hast du jemals ein Harry Potterbuch gelesen? Bei Ja bitte 1 und bei Nein bitte 0"); + int harry = getAnInteger(); + if (harry == 1 || harry == 0) { + System.out.println(harry); + } else { + harry = pruefen(harry); + System.out.println(harry); + } + + // sechste Frage + System.out.println("Wie viele Äpfel hast du heute schon gegessen?"); + int apfel = getAnInteger(); + if (apfel > 0) { + System.out.println(apfel); + } else { + while (apfel <= 0) { + System.out.println("Versuches es nochmal. Die Zahl muss positiv sein."); + apfel = getAnInteger(); + } + } + + // siebte Frage + System.out.println("Wie viele Veranstaltungen hattest du heute schon?"); + int anzahl = getAnInteger(); + if (anzahl > 0) { + System.out.println(anzahl); + } else { + while (anzahl <= 0) { + System.out.println("Versuches es nochmal. Die Zahl muss positiv sein."); + anzahl = getAnInteger(); + } + } + + // achte Frage + System.out.println("Was würdest du statt der Vorlesung machen? Lernen? Bei Ja bitte 1 und bei Nein bitte 0"); + int lernen = getAnInteger(); + if (lernen == 1 || lernen == 0) { + System.out.println(lernen); + } else { + lernen = pruefen(lernen); + System.out.println(lernen); + } + if (lernen == 1) + System.out.println("Wenn du das sagst, aber lueg dich doch bitte nicht selbst an."); + + // neunte Frage + System.out.println("Wuerdest du dir ein gelbes Auto kaufen? Bei Ja bitte 1 und bei Nein bitte 0"); + int gelb = getAnInteger(); + if (gelb == 1 || gelb == 0) { + System.out.println(gelb); + } else { + gelb = pruefen(gelb); + System.out.println(gelb); + } + + // Auswertung + + String antwort = ergebnis(alter, lernen, gelb, apfel, mot, harry, fruehstueck, anzahl); + return antwort; + + } +//nicht testbar + public static int skalaTest(int answer) { + System.out.println("Try again. Nur Werte zwischen 1 und 10 sind erlaubt."); + int b = getAnInteger(); + if (b >= 1 && b <= 10) { + return b; + } + skalaTest(b); + return -1; + } +//nicht testbar + public static int getAnInteger() { + Scanner in = new Scanner(System.in); + while (true) { + try { + return in.nextInt(); + } catch (InputMismatchException e) { + in.next(); + System.out.println("Das ist kein Integer. Try again."); + } + } + } + + //Nicht testbar + public static int pruefen(int answer) { + System.out.println("Try again. Nur 1 und 0 sind erlaubt."); + int b = getAnInteger(); + if (b == 1 || b == 0) { + return b; + } + pruefen(b); + return 1; + } + +} diff --git a/src/main/java/com/ugsbo/entscheider/package-info.java b/src/main/java/com/ugsbo/entscheider/package-info.java new file mode 100644 index 0000000..1d5b0b5 --- /dev/null +++ b/src/main/java/com/ugsbo/entscheider/package-info.java @@ -0,0 +1,8 @@ +/** + * + */ +/** + * @author bruec + * + */ +package com.ugsbo.entscheider; \ No newline at end of file diff --git a/src/main/java/com/ugsbo/gui/BasicGuiController.java b/src/main/java/com/ugsbo/gui/BasicGuiController.java new file mode 100644 index 0000000..a34ee08 --- /dev/null +++ b/src/main/java/com/ugsbo/gui/BasicGuiController.java @@ -0,0 +1,46 @@ +package com.ugsbo.gui; + +import javafx.fxml.FXML; +import javafx.scene.control.*; + +public class BasicGuiController { + + // Hier werden die fx:id Attribute verknuepft. + @FXML + private Button matrixCalc; + @FXML + private Button app2; //Fuer VokabelKartenSchreiber + @FXML + private Button app3; + @FXML + private Button app4; + + /** + * Konstructor is called before initialize() + */ + public BasicGuiController() { + // Setup of some Fields could be defined here. + } + + /** + * Initializes the controller class. This method is automatically called after + * the fxml file has been loaded. + */ + @FXML + public void initialize() { + matrixCalc.setOnMouseClicked((event) -> { + MainApp.startMatrixCalcGUI(); + // System.out.println(event); + }); + app2.setOnMouseClicked((event) -> { + //System.out.println(event); + MainApp.startVokabelKartenSchreiber(); + }); + app3.setOnMouseClicked((event) -> { + System.out.println(event); + }); + app4.setOnMouseClicked((event) -> { + System.out.println(event); + }); + } +} \ No newline at end of file diff --git a/src/main/java/com/ugsbo/gui/MainApp.java b/src/main/java/com/ugsbo/gui/MainApp.java index 4a0dafe..04c0635 100644 --- a/src/main/java/com/ugsbo/gui/MainApp.java +++ b/src/main/java/com/ugsbo/gui/MainApp.java @@ -1,8 +1,77 @@ package com.ugsbo.gui; -public class MainApp { +import java.io.IOException; +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.*; +import javafx.stage.Stage; + +/** + * Runs the main Application and handles the loading of an FXML file. + */ +public class MainApp extends Application { + + /** + * The main() method is ignored in correctly deployed JavaFX application. main() + * serves only as fallback in case the application can not be launched through + * deployment artifacts, e.g., in IDEs with limited FX support. NetBeans ignores + * main(). + * + * @param args the command line arguments + */ public static void main(String[] args) { - System.out.println("HelloWorld!"); + launch(args); + } + + /** + * Starts the Main GUI, will be called from JavaFx. + */ + @Override + public void start(Stage stage) { + createStageFromFXML(stage, "BasicGui"); + } + + /** + * Loades the FXML file and the Default CSS. + * + * @param stage The Stage will be passed over from JavaFx + * @param fxmlFileName Only the Filename of the fxml file wich sould be loaded + */ + private void createStageFromFXML(Stage stage, String fxmlFileName) { + // Gettring the FXML loader to load the File. + FXMLLoader loader = new FXMLLoader(getClass().getResource(fxmlFileName + ".fxml")); + Parent root; + // trying to load the FXML and CSS file for the GUI with the fxmlFileName. + try { + root = loader.load(); + Scene basicGUI = new Scene(root); + basicGUI.getStylesheets().add(getClass().getResource("styles.css").toExternalForm()); + // Setting the Title of the + stage.setTitle("Ultra geile Studenten Benutzeroberfläche"); + // set Resizeable to false, in oder to block resizeing though the User. + stage.setResizable(false); + stage.setScene(basicGUI); + } catch (IOException e) { + System.out.println(".FXML or .css File can not be found."); + e.printStackTrace(); + } + stage.show(); + } + + public static void startVokabelKartenSchreiber(){ + Stage stage = new Stage(); + MainApp main = new MainApp(); + main.createStageFromFXML(stage, "Voabelkartenschreiber"); } + + /** + * Startet eine Instanz der MatrixCalcGui. + */ + public static void startMatrixCalcGUI() { + Stage stage = new Stage(); + MainApp app = new MainApp(); + app.createStageFromFXML(stage, "matrixCalcGui"); + } + } diff --git a/src/main/java/com/ugsbo/gui/StartApplication.java b/src/main/java/com/ugsbo/gui/StartApplication.java new file mode 100644 index 0000000..38cccea --- /dev/null +++ b/src/main/java/com/ugsbo/gui/StartApplication.java @@ -0,0 +1,8 @@ +package com.ugsbo.gui; + +public class StartApplication { + + public static void main(String[] args) { + MainApp.main(args); + } +} \ No newline at end of file diff --git a/src/main/java/com/ugsbo/matrixcalc/MatrixCalcController.java b/src/main/java/com/ugsbo/matrixcalc/MatrixCalcController.java new file mode 100644 index 0000000..f857eb0 --- /dev/null +++ b/src/main/java/com/ugsbo/matrixcalc/MatrixCalcController.java @@ -0,0 +1,273 @@ +package com.ugsbo.matrixcalc; + +import javafx.fxml.FXML; +import javafx.scene.control.*; +import javafx.scene.text.Text; +import javafx.scene.text.TextAlignment; + +import java.util.ArrayList; + +public class MatrixCalcController { + + private static final String MULTIPLICATION_STRING = "multiplication"; + private static final String ADDITION_STRING = "addition"; + private static final String SUBSTRACTION_STRING = "substract"; + private static final String TRANPOSE_STRING = "transpose"; + private static final String CALCDETERMINAT_STRING = "calcDeterminate"; + + // The fx:id Attributes will be bind here. + @FXML + private Button multiplyButton, addButton, DetAButton, DetBButton, substractButton, transposeButton; + @FXML + private Text errorText, outputText; + @FXML + private TextArea matrixATextArea, matrixBTextArea; + + private MatrixCalcMath math = new MatrixCalcMath(); + private MatrixCalcIOUtils util = new MatrixCalcIOUtils(); + + /** + * Konstructor is called before initialize() + */ + public MatrixCalcController() { + // Setup of some Fields could be defined here. + } + + /** + * Initializes the controller class. This method is automatically called after + * the fxml file has been loaded. + */ + @FXML + public void initialize() { + /** + * Convert Strings to matricies, multiply them and output the result. + */ + multiplyButton.setOnMouseClicked((event) -> { + String stringMatrixA = matrixATextArea.getText(); + String stringMatrixB = matrixBTextArea.getText(); + String[] stringMatrix = { stringMatrixA, stringMatrixB }; + + checkInputAndDisplayIfInputIsNotValid(stringMatrix, 2); + + ArrayList matricies = new ArrayList(); + matricies.add(util.stringToMatrix(stringMatrixA)); + matricies.add(util.stringToMatrix(stringMatrixB)); + + invokeOperation(matricies, MULTIPLICATION_STRING); + }); + + /** + * Convert a String to a matrix, transpose it and output the result. + */ + transposeButton.setOnMouseClicked((event) -> { + String stringMatrixA = matrixATextArea.getText(); + String[] stringMatrix = { stringMatrixA, "" }; + + checkInputAndDisplayIfInputIsNotValid(stringMatrix, 1); + + ArrayList matricies = new ArrayList(); + matricies.add(util.stringToMatrix(stringMatrixA)); + + invokeOperation(matricies, TRANPOSE_STRING); + }); + + /** + * Convert Strings to matricies, add them and output the result. + */ + addButton.setOnMouseClicked((event) -> { + String stringMatrixA = matrixATextArea.getText(); + String stringMatrixB = matrixBTextArea.getText(); + String[] stringMatrix = { stringMatrixA, stringMatrixB }; + + checkInputAndDisplayIfInputIsNotValid(stringMatrix, 2); + + ArrayList matricies = new ArrayList(); + matricies.add(util.stringToMatrix(stringMatrixA)); + matricies.add(util.stringToMatrix(stringMatrixB)); + + invokeOperation(matricies, ADDITION_STRING); + }); + + /** + * Convert Strings to matricies, substract them and output the result. + */ + substractButton.setOnMouseClicked((event) -> { + String stringMatrixA = matrixATextArea.getText(); + String stringMatrixB = matrixBTextArea.getText(); + String[] stringMatrix = { stringMatrixA, stringMatrixB }; + + checkInputAndDisplayIfInputIsNotValid(stringMatrix, 2); + + ArrayList matricies = new ArrayList(); + matricies.add(util.stringToMatrix(stringMatrixA)); + matricies.add(util.stringToMatrix(stringMatrixB)); + + invokeOperation(matricies, SUBSTRACTION_STRING); + }); + + /** + * Convert the String of the left inputField to a matrix, calculate the Determinate and output it. + */ + DetAButton.setOnMouseClicked((event) -> { + String stringMatrixA = matrixATextArea.getText(); + String[] stringMatrix = { stringMatrixA, "" }; + + checkInputAndDisplayIfInputIsNotValid(stringMatrix, 1); + + ArrayList matricies = new ArrayList(); + matricies.add(util.stringToMatrix(stringMatrixA)); + + invokeOperation(matricies, CALCDETERMINAT_STRING); + }); + + /** + * Convert the String of the right inputField to a matrix, calculate the Determinate and output it. + */ + DetBButton.setOnMouseClicked((event) -> { + String stringMatrixB = matrixBTextArea.getText(); + String[] stringMatrix = { "", stringMatrixB }; + + checkInputAndDisplayIfInputIsNotValid(stringMatrix, 1); + + ArrayList matricies = new ArrayList(); + matricies.add(util.stringToMatrix(stringMatrixB)); + + invokeOperation(matricies, CALCDETERMINAT_STRING); + }); + } + + /** + * Invokes the needed operations form the MatrixCalcMath class + * @param matricies Contains both Matricies or onely one Matrix + * @param operation One of the global Constats to select wich Operation is needed. + */ + private void invokeOperation(ArrayList matricies, String operation) { + if (matricies.size() == 2) { + if (operation.equals(MULTIPLICATION_STRING)) { + try { + double[][] result = math.matrixMultiplication(matricies.get(0), matricies.get(1)); + + String DisplayableString = util.outputMatrixToOutputText(result); + + outputText.setText(DisplayableString); + outputText.setTextAlignment(TextAlignment.CENTER); + } catch (IllegalArgumentException e) { + + outputText.setText(e.getMessage()); + outputText.setTextAlignment(TextAlignment.CENTER); + } + } else if (operation.equals(ADDITION_STRING)) { + try { + double[][] result = math.matrixAddition(matricies.get(0), matricies.get(1)); + + String DisplayableString = util.outputMatrixToOutputText(result); + + outputText.setText(DisplayableString); + outputText.setTextAlignment(TextAlignment.CENTER); + } catch (IllegalArgumentException e) { + + outputText.setText(e.getMessage()); + outputText.setTextAlignment(TextAlignment.CENTER); + } + } else if (operation.equals(SUBSTRACTION_STRING)) { + try { + double[][] result = math.matrixSubstraction(matricies.get(0), matricies.get(1)); + + String DisplayableString = util.outputMatrixToOutputText(result); + + outputText.setText(DisplayableString); + outputText.setTextAlignment(TextAlignment.CENTER); + } catch (IllegalArgumentException e) { + + outputText.setText(e.getMessage()); + outputText.setTextAlignment(TextAlignment.CENTER); + } + } + }else if (matricies.size() == 1) { + if (operation.equals(TRANPOSE_STRING)) { + try { + double[][] result = math.matrixTransponation(matricies.get(0)); + + String DisplayableString = util.outputMatrixToOutputText(result); + + outputText.setText(DisplayableString); + outputText.setTextAlignment(TextAlignment.CENTER); + } catch (IllegalArgumentException e) { + + outputText.setText(e.getMessage()); + outputText.setTextAlignment(TextAlignment.CENTER); + } + } + if (operation.equals(CALCDETERMINAT_STRING)) { + try { + double result = math.calcDeterminat(matricies.get(0)); + + String DisplayableString = Double.toString(result); + + outputText.setText(DisplayableString); + outputText.setTextAlignment(TextAlignment.CENTER); + } catch (IllegalArgumentException e) { + + outputText.setText(e.getMessage()); + outputText.setTextAlignment(TextAlignment.CENTER); + } catch (Exception e){ + + outputText.setText(e.getMessage()); + outputText.setTextAlignment(TextAlignment.CENTER); + } + } + } + } + + /** + * Checks the Input and Displays it if the Input is valid. + * + * @param stringMatrix Contains both input matrices if + * numberOfMarriciesToMatch is 2. If the number + * is 1 than one of them has to be a empty String + * @param numberOfMatricesToMatch If the number is 1 onely one Marix will be + * verifyed and the other one needs to be an empty + * String in the stringMatrix + */ + private void checkInputAndDisplayIfInputIsNotValid(String[] stringMatrix, int numberOfMatricesToMatch) { + if (numberOfMatricesToMatch == 1 && !stringMatrix[0].equals("")) { + try { + util.checkInput(stringMatrix[0]); + } catch (Exception e) { + outputText.setText(e.getMessage() + "A"); + outputText.setTextAlignment(TextAlignment.CENTER); + } + } else if (numberOfMatricesToMatch == 1 && !stringMatrix[1].equals("")) { + try { + util.checkInput(stringMatrix[1]); + } catch (Exception e) { + outputText.setText(e.getMessage() + "B"); + outputText.setTextAlignment(TextAlignment.CENTER); + } + } else if (numberOfMatricesToMatch == 2 && !stringMatrix[0].equals("") && !stringMatrix[1].equals("")) { + try { + util.checkInput(stringMatrix[0]); + } catch (Exception e) { + outputText.setText(e.getMessage() + "A"); + outputText.setTextAlignment(TextAlignment.CENTER); + } + + try { + util.checkInput(stringMatrix[1]); + } catch (Exception e) { + outputText.setText(e.getMessage() + "B"); + outputText.setTextAlignment(TextAlignment.CENTER); + } + } else if (stringMatrix[0].equals("")) { + + outputText.setText("Pease insert MatrixA"); + outputText.setTextAlignment(TextAlignment.CENTER); + + } else if (stringMatrix[1].equals("")) { + + outputText.setText("Pease insert MatrixB"); + outputText.setTextAlignment(TextAlignment.CENTER); + } + + } +} \ No newline at end of file diff --git a/src/main/java/com/ugsbo/matrixcalc/MatrixCalcIOUtils.java b/src/main/java/com/ugsbo/matrixcalc/MatrixCalcIOUtils.java new file mode 100644 index 0000000..e929081 --- /dev/null +++ b/src/main/java/com/ugsbo/matrixcalc/MatrixCalcIOUtils.java @@ -0,0 +1,97 @@ +package com.ugsbo.matrixcalc; + +import java.util.ArrayList; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class MatrixCalcIOUtils { + /** + * Prints a given 2D-Array to the output Textfield. + * + * @param output2DArray The Array that gets Displayed + */ + protected String outputMatrixToOutputText(double[][] output2DArray) { + // convert array to String + String DisplayableString = convertsArrayToStringInOrderToDisplayIt(output2DArray); + // Display output + return DisplayableString; + } + + /** + * Converts 2D-Array to String in order to Display it. + * + * @param array2D The array wich will be converted to an Displayable String + * @return The Displayable String + */ + protected String convertsArrayToStringInOrderToDisplayIt(double[][] array2D) { + String displayableString = ""; + for (int i = 0; i < array2D.length; i++) { + for (int j = 0; j < array2D[0].length; j++) { + displayableString += array2D[i][j] + " "; + } + displayableString += "\n\n"; + } + return displayableString; + } + + /** + * Checks if the Input is Valid, with Regex. Returns true if the Matrix can be + * matched by the regular Expression. + * + * @param matrix It is the InputMatrix + * @return True if the Matrix is valid Input. + */ + protected void checkInput(String matrix) throws IllegalArgumentException { + if (matrix.length() == 0) { + throw new IllegalArgumentException("Please insert a Matrix"); + } + + // Matches digits witch following spaces 1 to 3 times + String row1 = "(\\d*\\u0020*){1,3}"; + // Matches newlineCurrierReturn followed by digits witch following spaces 1 to + // 3 times + String row2 = "(\\n){0,3}(\\d*\\u0020*){0,3}"; + String row3 = "(\\n){0,3}(\\d*\\u0020*){0,3}"; + + // TODO for verion 2 get the input check more stricktly missing matrix slots are allowed. + + Pattern p = Pattern.compile(row1 + row2 + row3); + Matcher m = p.matcher(matrix); + + if(!m.matches()){ + throw new IllegalArgumentException("A Matrix is not in the right format, Matrix "); + } + } + + /** + * Converts a String form the Inputfield to an 2D-Array aka Matrix. + * + * @param stringMatrix The String form the Inputfield + * @return Matrix as a 2D-Array + */ + public double[][] stringToMatrix(String stringMatrix) { + + ArrayList singleNumbersArr = new ArrayList(); + + // Splitting the strings into their rows + String[] singleNumbers = null; + String[] rows = stringMatrix.split("\n"); + for (int i = 0; i < rows.length; i++) { + // Splitting rows into their Numbers + singleNumbers = rows[i].split("\\s"); + singleNumbersArr.add(singleNumbers); + } + + int rowlength = singleNumbersArr.get(0).length; + int columCount = singleNumbersArr.size(); + double[][] matrix = new double[columCount][rowlength]; + + for (int columIndex = 0; columIndex < columCount; columIndex++) { + for (int rowIndex = 0; rowIndex < singleNumbers.length; rowIndex++) { + matrix[columIndex][rowIndex] = Double.parseDouble(singleNumbersArr.get(columIndex)[rowIndex]); + } + } + return matrix; + } + +} \ No newline at end of file diff --git a/src/main/java/com/ugsbo/matrixcalc/MatrixCalcMath.java b/src/main/java/com/ugsbo/matrixcalc/MatrixCalcMath.java new file mode 100644 index 0000000..5cd807b --- /dev/null +++ b/src/main/java/com/ugsbo/matrixcalc/MatrixCalcMath.java @@ -0,0 +1,228 @@ +package com.ugsbo.matrixcalc; + +/** + * Contains all basic matrix math calculations. + */ +public class MatrixCalcMath { + + /** + * Mutliplys matrixA and matrixB. + * + * @param matrixA The Inputmatrix A (right TextArea in the GUI) + * @param matrixB The Inputmatrix B (left TextArea in the GUI) + * @return The Matrixproduct of the matricies A and B + */ + public double[][] matrixMultiplication(double[][] matrixA, double[][] matrixB) { + if (checkIfMatriciesAreLinked(matrixA, matrixB)) { + int rowOfResultMatrix = matrixA.length; + int columOfResultMatrix = matrixB[0].length; + int ColumsOfMatA = matrixA[0].length; + double[][] result = new double[rowOfResultMatrix][columOfResultMatrix]; + + for (int rowResult = 0; rowResult < rowOfResultMatrix; rowResult++) { + for (int columResult = 0; columResult < columOfResultMatrix; columResult++) { + for (int columOfA = 0; columOfA < ColumsOfMatA; columOfA++) { + result[rowResult][columResult] += matrixA[rowResult][columOfA] * matrixB[columOfA][columResult]; + } + } + } + return result; + } else { + throw new IllegalArgumentException("Matricies must be linked"); + } + } + + /** + * checks if matrixA and matrixB are linked to know if it is possible to + * multiply them. If they are linked it is possible. + * + * @param matrixA The Inputmatrix A (right TextArea in the GUI) + * @param matrixB The Inputmatrix B (left TextArea in the GUI) + * @return true if you can Muliply A with B false if not. + */ + public boolean checkIfMatriciesAreLinked(double[][] matrixA, double[][] matrixB) { + if (matrixA == null) { + return false; + } + if (matrixA.length == 0) { + return false; + } + if (matrixA[0].length == matrixB.length) { + return true; + } + return false; + } + + /** + * Adds two matroices A and B. Adding matrix A to matrix B is the same as adding + * B to A. + * + * @param matrixA The Inputmatrix A (right TextArea in the GUI) + * @param matrixB The Inputmatrix B (left TextArea in the GUI) + * @return The Matrixsum of matrix A and matrix B + */ + public double[][] matrixAddition(double[][] matrixA, double[][] matrixB) { + if (checkIfMatriciesAreTheSameDimension(matrixA, matrixB)) { + double[][] result = new double[matrixA.length][matrixA[0].length]; + for (int rows = 0; rows < matrixA.length; rows++) { + for (int colums = 0; colums < matrixA[0].length; colums++) { + result[rows][colums] = matrixA[rows][colums] + matrixB[rows][colums]; + } + } + return result; + } else { + throw new IllegalArgumentException("Matricies need to have the same Dimensions"); + } + } + + /** + * In order to adding two Matricies they must have the same Dimensions. This + * Methode checks if this is the case. + * + * @param matrixA The Inputmatrix A (right TextArea in the GUI) + * @param matrixB The Inputmatrix B (left TextArea in the GUI) + * @return true if the Dimensions of Matrix A equals the Dimensions Matrix B + */ + public boolean checkIfMatriciesAreTheSameDimension(double[][] matrixA, double[][] matrixB) { + if (matrixA == null || matrixA.length == 0) { + return false; + } + if (matrixA[0] == null) { + return false; + } + if (matrixA.length == matrixB.length && matrixA[0].length == matrixB[0].length) { + return true; + } else { + return false; + } + + } + + /** + * Substracts matrix A by the matrix B. Substaction for Matrices is just the + * substraction of each component with thier coorsponding component. + * + * @param matrixA The Inputmatrix A (right TextArea in the GUI) + * @param matrixB The Inputmatrix B (left TextArea in the GUI + * @return matrix A substracted by matrix B + */ + public double[][] matrixSubstraction(double[][] matrixA, double[][] matrixB) { + if (checkIfMatriciesAreTheSameDimension(matrixA, matrixB)) { + double[][] result = new double[matrixA.length][matrixA[0].length]; + for (int rows = 0; rows < matrixA.length; rows++) { + for (int colums = 0; colums < matrixA[0].length; colums++) { + result[rows][colums] = matrixA[rows][colums] - matrixB[rows][colums]; + } + } + return result; + } else { + throw new IllegalArgumentException("Matricies need to have the same Dimensions"); + } + } + + /** + * Transposes the Input Matrix. Swaps rows with colums. + * + * @param matrixA The Inputmatrix A wich will be Transposed + * @return The Transposed matrix of matrix A + */ + public double[][] matrixTransponation(double[][] matrixA) { + if (matrixA == null) { + throw new IllegalArgumentException("Matricies need to have the same Dimensions"); + } + if (matrixA.length == 0) { + throw new IllegalArgumentException("Matricies need to have the same Dimensions"); + } + if (matrixA[0] == null) { + throw new IllegalArgumentException("Matricies need to have the same Dimensions"); + } + int columCountResult = matrixA.length; + int rowCountResult = matrixA[0].length; + double[][] result = new double[rowCountResult][columCountResult]; + for (int row = 0; row < rowCountResult; row++) { + for (int colum = 0; colum < columCountResult; colum++) { + result[row][colum] = matrixA[colum][row]; + } + } + return result; + } + + /** + * Calculates the Determinant of a Matrix. + * + * @param matrixA The Inputmatrix + * @return The Determinant of the Matrix A + */ + public double calcDeterminat(double[][] matrixA) throws IllegalArgumentException{ + // checking if a Determinant can be calculated. + double result = 0.0; + if (checkIfMatrixIsQuadradtic(matrixA)) { + if (getMatrixRowCount(matrixA) == 2) { + result = calc2by2Determinant(matrixA); + } else if (getMatrixRowCount(matrixA) == 3) { + result = calc3by3Determinant(matrixA); + + } else { + throw new IllegalArgumentException("Matrix is not 2 by 2 or 3 by 3"); + } + + } else { + throw new IllegalArgumentException("Matrix must be Quadratic"); + } + return result; + } + + /** + * Calculates the Determinat of an three by three Matrix. + * + * @param matrixA The Inputmatrix form wich the Determinat will be calculated + * @return the Determinant of the Matrix + */ + private double calc3by3Determinant(double[][] matrixA) { + double result = matrixA[0][0] * matrixA[1][1] * matrixA[2][2] + matrixA[0][1] * matrixA[1][2] * matrixA[2][0] + + matrixA[0][2] * matrixA[1][0] * matrixA[2][1] - matrixA[0][0] * matrixA[1][2] * matrixA[2][1] + - matrixA[0][1] * matrixA[1][0] * matrixA[2][2] - matrixA[0][2] * matrixA[1][1] * matrixA[2][0]; + return result; + } + + /** + * Calculates the Determinat of an two by two Matrix. + * + * @param matrixA The Inputmatrix form wich the Determinat will be calculated + * @return the Determinant of the Matrix + */ + private double calc2by2Determinant(double[][] matrixA) { + double result = matrixA[0][0] * matrixA[1][1] - matrixA[0][1] * matrixA[1][0]; + return result; + } + + /** + * Returns the Number of rows of a Matrix. + * + * @param matrixA the Inputmatrix form wich the rows will be counted + * @return Number of rows + */ + private int getMatrixRowCount(double[][] matrixA) { + return matrixA.length; + } + + /** + * Checks if the rows and colums of an Matrix are equal. If they are equal the + * Matrix is Quadratic and the function will return true. + * + * @param matrixA the Inputmatrix for wich the rows and colums will be compared + * @return isQuadratic + */ + private boolean checkIfMatrixIsQuadradtic(double[][] matrixA) { + if (matrixA == null) { + return false; + } + if (matrixA[0] == null) { + return false; + } + if (matrixA.length == matrixA[0].length) { + return true; + } + return false; + } +} \ No newline at end of file diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java deleted file mode 100644 index a48c156..0000000 --- a/src/main/java/module-info.java +++ /dev/null @@ -1,8 +0,0 @@ -module UGSBO { - requires javafx.controls; - requires javafx.fxml; - - opens com.ugsbo.gui to javafx.fxml; - - exports com.ugsbo.gui; -} \ No newline at end of file diff --git a/src/main/java/ugsbo/com/buchhaltung/Auswertung.java b/src/main/java/ugsbo/com/buchhaltung/Auswertung.java new file mode 100644 index 0000000..fb9ad01 --- /dev/null +++ b/src/main/java/ugsbo/com/buchhaltung/Auswertung.java @@ -0,0 +1,15 @@ +package ugsbo.com.buchhaltung; + +public class Auswertung { + + public static void main(String[] args) { + // TODO Auto-generated method stub + Blockchain Work = new Blockchain(); + Work.add(50); + Work.add(-20); + + System.out.println(Work.kontostand()); + System.out.print(Work.toString()); + } + +} diff --git a/src/main/java/ugsbo/com/buchhaltung/Block.java b/src/main/java/ugsbo/com/buchhaltung/Block.java new file mode 100644 index 0000000..b315519 --- /dev/null +++ b/src/main/java/ugsbo/com/buchhaltung/Block.java @@ -0,0 +1,67 @@ +package ugsbo.com.buchhaltung; + +import java.security.MessageDigest; + +public class Block { + + + int data; + int kontostand; + Block vorher; + + String ownHash; + String previousHash; + + + //erste Block + public Block(int data) { + this.data = data; + ownHash = createNewHash(Integer.toString(data)); + + kontostand = this.data; + + this.vorher = null; + this.previousHash = null; + } + + //Alle anderen Blöcke + public Block(int data, Block vorher, String previousHash, int konto) { + this.data = data; + ownHash = createNewHash(Integer.toString(data)+previousHash); + + kontostand = konto + this.data; + + this.vorher = vorher; + this.previousHash = previousHash; + } + + private String createNewHash(String input) { + try { + MessageDigest digest = MessageDigest.getInstance("SHA-256"); + //Applies sha256 to our input, + byte[] hash = digest.digest(input.getBytes("UTF-8")); + StringBuffer hexString = new StringBuffer(); // This will contain hash as hexidecimal + for (int i = 0; i < hash.length; i++) { + String hex = Integer.toHexString(0xff & hash[i]); + if(hex.length() == 1) hexString.append('0'); + hexString.append(hex); + } + return hexString.toString(); + } + catch(Exception e) { + throw new RuntimeException(e); + } + } + + public int getKontostand() { + return kontostand; + } + + public Block getVorher() { + return vorher; + } + + public String getHash() { + return ownHash; + } +} diff --git a/src/main/java/ugsbo/com/buchhaltung/Blockchain.java b/src/main/java/ugsbo/com/buchhaltung/Blockchain.java new file mode 100644 index 0000000..987b2b1 --- /dev/null +++ b/src/main/java/ugsbo/com/buchhaltung/Blockchain.java @@ -0,0 +1,32 @@ +package ugsbo.com.buchhaltung; + +import com.google.gson.*; + +public class Blockchain { + + Block Workingobjekt; + + + public Blockchain() { + Workingobjekt = new Block(0); + } + + + public void add(int eingabe) { + Block newWorkingobjekt = new Block(eingabe, Workingobjekt, Workingobjekt.getHash(), Workingobjekt.getKontostand()); + + Workingobjekt = newWorkingobjekt; + } + + + public int kontostand() { + return Workingobjekt.getKontostand(); + } + + public String toString() { + String JSON = new GsonBuilder().setPrettyPrinting().create().toJson(Workingobjekt); + return JSON; + } + + +} diff --git a/src/main/java/ugsbo/com/notenSpeicher/Auswertung.java b/src/main/java/ugsbo/com/notenSpeicher/Auswertung.java new file mode 100644 index 0000000..09ce0fc --- /dev/null +++ b/src/main/java/ugsbo/com/notenSpeicher/Auswertung.java @@ -0,0 +1,15 @@ +package ugsbo.com.notenSpeicher; + +public class Auswertung { + + public static void main(String[] args) { + NotenKette Work = new NotenKette("Prog 1", 1); + Work.add("Prog 2", 2); + Work.add("Wi", 3); + + System.out.println(Work.durchschnitt() + "\n"); + + System.out.print(Work.toString()); + } + +} \ No newline at end of file diff --git a/src/main/java/ugsbo/com/notenSpeicher/Noten.java b/src/main/java/ugsbo/com/notenSpeicher/Noten.java new file mode 100644 index 0000000..31f61fd --- /dev/null +++ b/src/main/java/ugsbo/com/notenSpeicher/Noten.java @@ -0,0 +1,77 @@ +package ugsbo.com.notenSpeicher; + +import java.security.MessageDigest; + +public class Noten { + + + String Fach; + int Note; + double durchschnitt; + Noten vorher; + + String ownHash; + String previousHash; + + public Noten(String eingabeFach, int eingabeNote) { + Fach = eingabeFach; + Note = eingabeNote; + durchschnitt = eingabeNote; + + vorher = null; + previousHash = null; + + ownHash = createNewHash(eingabeFach); + } + + public Noten(String eingabeFach, int eingabeNote, String previousHash, double durchschnitt, Noten vorher) { + Fach = eingabeFach; + Note = eingabeNote; + ownHash = createNewHash(eingabeFach+previousHash); + + this.durchschnitt = (durchschnitt+eingabeNote)/2; + + this.vorher = vorher; + this.previousHash = previousHash; + } + + private String createNewHash(String input) { + try { + MessageDigest digest = MessageDigest.getInstance("SHA-256"); + //Applies sha256 to our input, + byte[] hash = digest.digest(input.getBytes("UTF-8")); + StringBuffer hexString = new StringBuffer(); // This will contain hash as hexidecimal + for (int i = 0; i < hash.length; i++) { + String hex = Integer.toHexString(0xff & hash[i]); + if(hex.length() == 1) hexString.append('0'); + hexString.append(hex); + } + return hexString.toString(); + } + catch(Exception e) { + throw new RuntimeException(e); + } + } + + + public String getFach() { + return Fach; + } + + public int getNote() { + return Note; + } + + public double getDurchschnitt() { + return durchschnitt; + } + + public Noten getVorher() { + return vorher; + } + + public String getOwnHash() { + return ownHash; + } + +} diff --git a/src/main/java/ugsbo/com/notenSpeicher/NotenKette.java b/src/main/java/ugsbo/com/notenSpeicher/NotenKette.java new file mode 100644 index 0000000..d749bbd --- /dev/null +++ b/src/main/java/ugsbo/com/notenSpeicher/NotenKette.java @@ -0,0 +1,38 @@ +package ugsbo.com.notenSpeicher; + +public class NotenKette { + + Noten Workingobjekt; + + public NotenKette(String eingabeFach, int eingabeNote) { + Workingobjekt = new Noten(eingabeFach, eingabeNote); + } + + public double durchschnitt() { + return Workingobjekt.getDurchschnitt(); + } + + public void add(String eingabeFach, int eingabeNote) { + if (eingabeNote == 0) return; + + Noten newWorkingObjekt = new Noten(eingabeFach,eingabeNote, Workingobjekt.previousHash, Workingobjekt.durchschnitt, Workingobjekt); + Workingobjekt = newWorkingObjekt; + } + + public String toString() { + String erg = ""; + Noten temp = Workingobjekt; + + while (true) { + erg += temp.getFach() + "\t"+ temp.getNote() +"\n"; + + temp = temp.getVorher(); + + if (temp == null) { + return erg; + } + + } + } + +} diff --git a/src/main/resources/com/ugsbo/gui/BasicGui.fxml b/src/main/resources/com/ugsbo/gui/BasicGui.fxml new file mode 100644 index 0000000..d591c5a --- /dev/null +++ b/src/main/resources/com/ugsbo/gui/BasicGui.fxml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + +