commit 5c6877fe23238c58344a0d526f13f716d6e2998f Author: AlexBa16 <139718933+AlexBa16@users.noreply.github.com> Date: Tue Nov 19 08:47:16 2024 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..a55e7a1 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/icon.svg b/.idea/icon.svg new file mode 100644 index 0000000..dc423f6 --- /dev/null +++ b/.idea/icon.svg @@ -0,0 +1,54745 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..3266772 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/.idea/libraries/lib.xml b/.idea/libraries/lib.xml new file mode 100644 index 0000000..eb3bb1a --- /dev/null +++ b/.idea/libraries/lib.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..da4ba47 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..f3480fa --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SEW_Bachinger_2024.25.iml b/SEW_Bachinger_2024.25.iml new file mode 100644 index 0000000..580b561 --- /dev/null +++ b/SEW_Bachinger_2024.25.iml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/UE00_Other/MEDT/Plakat_CODING_Contest.java b/src/UE00_Other/MEDT/Plakat_CODING_Contest.java new file mode 100644 index 0000000..02b1726 --- /dev/null +++ b/src/UE00_Other/MEDT/Plakat_CODING_Contest.java @@ -0,0 +1,54 @@ +package UE00_Other.MEDT; + +import java.util.ArrayList; +import java.util.List; + +public class Plakat_CODING_Contest { + + static final String participation_fee = "20€"; + static final String grand_prize = "Macbook Pro M4"; + + public static List generateFibonacci(int length) { + List sequence = new ArrayList<>(); + int a = 0, b = 1; + while (sequence.size() < length) { + sequence.add(a); + int temp = a; + a = b; + b = temp + b; + } + return sequence; + } + public static List generateRandomNumbers(int count) { + List numbers = new ArrayList<>(); + for (int i = 0; i < count; i++) numbers.add((int) (Math.random() * 100) + 1); + return numbers; + } + public static int sumPrimes(List numbers) { + int sum = 0; + for (int number : numbers) if (isPrime(number)) sum += number; + return sum; + } + public static boolean isPrime(int number) { + if (number <= 1) return false; + for (int i = 2; i <= Math.sqrt(number); i++) if (number % i == 0) return false; + return true; + } + static void depthFirstSearch(Node node, List visited) { + if (node == null || visited.contains(node)) return; + System.out.println("Visited: " + node.name); + visited.add(node); + for (Node neighbor : node.neighbors) depthFirstSearch(neighbor, visited); + } + static class Node { + String name; + List neighbors; + Node(String name) { + this.name = name; + this.neighbors = new ArrayList<>(); + } + void addNeighbor(Node neighbor) { + neighbors.add(neighbor); + } + } +} \ No newline at end of file diff --git a/src/UE01_030924_Wiederholung/BankwesenTest.java b/src/UE01_030924_Wiederholung/BankwesenTest.java new file mode 100644 index 0000000..4d62fc7 --- /dev/null +++ b/src/UE01_030924_Wiederholung/BankwesenTest.java @@ -0,0 +1,115 @@ +package UE01_030924_Wiederholung; + +import static org.junit.jupiter.api.Assertions.*; + +public class BankwesenTest { + public static void main(String[] args) { + Girokonto girokonto = new Girokonto("AlexArm", 5); + Girokonto girokonto1 = new Girokonto("AlexReich", 1000, -5); + Girokonto girokonto2 = new Girokonto(null, -100, 0); + + Kreditkonto kreditkonto = new Kreditkonto("AlexArm", 5, -1000); + Kreditkonto kreditkonto1 = new Kreditkonto("AlexReich", 5, 1000); + Kreditkonto kreditkonto2 = new Kreditkonto(null, -5, 0); + + Sparbuch sparbuch = new Sparbuch(1000, 2); + Sparbuch sparbuch1 = new Sparbuch(-1000, 5); + Sparbuch sparbuch2 = new Sparbuch(5); + + testGirokonto(girokonto, girokonto1, girokonto2); + System.out.println("Girokonto Tests erfolgreich!"); + testKreditkonto(kreditkonto, kreditkonto1, kreditkonto2); + System.out.println("Kreditkonto Tests erfolgreich!"); + testSparbuch(sparbuch, sparbuch1, sparbuch2); + System.out.println("Sparbuch Tests erfolgreich!"); + + girokonto.speichereKontoauszug(); + girokonto1.speichereKontoauszug(); + girokonto2.speichereKontoauszug(); + + kreditkonto.speichereKontoauszug(); + kreditkonto1.speichereKontoauszug(); + kreditkonto2.speichereKontoauszug(); + + sparbuch.speichereKontoauszug(); + sparbuch1.speichereKontoauszug(); + sparbuch2.speichereKontoauszug(); + + System.out.println("\nGesamt Summe: " + berechneSumme(girokonto, girokonto1, girokonto2, kreditkonto, kreditkonto1, kreditkonto2, sparbuch, sparbuch1, sparbuch2)); + } + + public static void testGirokonto(Girokonto girokonto, Girokonto girokonto1, Girokonto girokonto2) { + assertEquals(girokonto.einzahlung(-100), 0); + assertEquals(girokonto.getKontostand(), 0); + assertEquals(girokonto.einzahlung(100), 100); + assertEquals(girokonto.getKontostand(), 100); + + assertFalse(girokonto.auszahlung(2000)); + assertEquals(girokonto.getKontostand(), 100); + assertTrue(girokonto1.auszahlung(200)); + assertEquals(girokonto1.getKontostand(), 800); + + assertEquals(girokonto1.getKontostand(), 800); + assertEquals(girokonto.getKontostand(), 100); + assertEquals(girokonto1.ueberweisung(girokonto, 50), 50); + assertEquals(girokonto1.getKontostand(), 750); + assertEquals(girokonto.getKontostand(), 150); + assertEquals(girokonto1.ueberweisung(girokonto, 5000), 0); + assertEquals(girokonto1.getKontostand(), 750); + assertEquals(girokonto.getKontostand(), 150); + assertEquals(girokonto1.ueberweisung(girokonto, -100), 0); + assertEquals(girokonto1.getKontostand(), 750); + assertEquals(girokonto.getKontostand(), 150); + + assertEquals(girokonto.toString(), "000001 - Girokonto von AlexArm: Zinssatz: 5.0%, Kontostand: 150.0"); + assertEquals(girokonto1.toString(), "000002 - Girokonto von AlexReich: Zinssatz: -5.0%, Kontostand: 750.0"); + assertEquals(girokonto2.toString(), "000003 - Girokonto von undefined: Zinssatz: 0.0%, Kontostand: -100.0"); + + girokonto.verrechneZinsen(); + girokonto1.verrechneZinsen(); + girokonto2.verrechneZinsen(); + + assertEquals(girokonto.toString(), "000001 - Girokonto von AlexArm: Zinssatz: 5.0%, Kontostand: 157.5"); + assertEquals(girokonto1.toString(), "000002 - Girokonto von AlexReich: Zinssatz: -5.0%, Kontostand: 712.5"); + assertEquals(girokonto2.toString(), "000003 - Girokonto von undefined: Zinssatz: 0.0%, Kontostand: -100.0"); + } + + public static void testKreditkonto(Kreditkonto kreditkonto, Kreditkonto kreditkonto1, Kreditkonto kreditkonto2) { + assertEquals(kreditkonto.einzahlung(-100), 0); + assertEquals(kreditkonto.getKontostand(), -1000); + assertEquals(kreditkonto.einzahlung(100), 100); + assertEquals(kreditkonto.getKontostand(), -900); + assertEquals(kreditkonto1.einzahlung(-100), 0); + assertEquals(kreditkonto1.getKontostand(), -1000); + assertEquals(kreditkonto1.einzahlung(100), 100); + assertEquals(kreditkonto1.getKontostand(), -900); + assertEquals(kreditkonto.toString(), "000004 - Kreditkonto von AlexArm: Zinssatz: 5.0%, Kontostand: -900.0"); + assertEquals(kreditkonto1.toString(), "000005 - Kreditkonto von AlexReich: Zinssatz: 5.0%, Kontostand: -900.0"); + assertEquals(kreditkonto2.toString(), "000006 - Kreditkonto von undefined: Zinssatz: -5.0%, Kontostand: -0.0"); + assertEquals(kreditkonto.einzahlung(900), 900); + assertEquals(kreditkonto.getKontostand(), 0); + assertEquals(kreditkonto1.einzahlung(1000), 900); + assertEquals(kreditkonto1.getKontostand(), 0); + } + + public static void testSparbuch(Sparbuch sparbuch, Sparbuch sparbuch1, Sparbuch sparbuch2) { + assertEquals(sparbuch.einzahlung(-100), 0); + assertEquals(sparbuch.getKontostand(), 1000); + assertEquals(sparbuch.einzahlung(100), 100); + assertEquals(sparbuch.getKontostand(), 1100); + + assertTrue(sparbuch.auszahlung(100)); + assertEquals(sparbuch.getKontostand(), 1000); + assertFalse(sparbuch1.auszahlung(200)); + assertEquals(sparbuch1.getKontostand(), -1000); + assertEquals(sparbuch.toString(), "000007 - Sparbuch: Zinssatz: 2.0%, Kontostand: 1000.0"); + assertEquals(sparbuch1.toString(), "000008 - Sparbuch: Zinssatz: 5.0%, Kontostand: -1000.0"); + assertEquals(sparbuch2.toString(), "000009 - Sparbuch: Zinssatz: 5.0%, Kontostand: 0.0"); + } + + public static double berechneSumme(Konto... kontos) { + double summe = 0; + for (Konto konto : kontos) summe += konto.getKontostand(); + return summe; + } +} \ No newline at end of file diff --git a/src/UE01_030924_Wiederholung/Girokonto.java b/src/UE01_030924_Wiederholung/Girokonto.java new file mode 100644 index 0000000..2144a88 --- /dev/null +++ b/src/UE01_030924_Wiederholung/Girokonto.java @@ -0,0 +1,41 @@ +package UE01_030924_Wiederholung; + +public class Girokonto extends Konto { + String name = "undefined"; + + public Girokonto(String name, double betrag, double zinssatz) { + super(betrag, zinssatz, "Girokonto"); + if (name != null) this.name = name; + } + + public Girokonto(String name, double zinssatz) { + super(zinssatz, "Girokonto"); + this.name = name; + } + + public double einzahlung(double betrag) { + if (betrag < 0) return 0; + this.kontostand += betrag; + this.buchungsvorgaenge.add("Einzahlung: " + betrag); + return betrag; + } + + public boolean auszahlung(double betrag) { + if (this.kontostand - betrag < 0) return false; + this.kontostand -= betrag; + this.buchungsvorgaenge.add("Auszahlung: " + betrag); + return true; + } + + public double ueberweisung(Konto empfaenger, double betrag) { + if (betrag < 0 || !auszahlung(betrag)) return 0; + empfaenger.einzahlung(betrag); + this.buchungsvorgaenge.add("Überweisung an " + kontonummer(empfaenger.kontonummer) + ": " + betrag); + return betrag; + } + + @Override + public String toString() { + return kontonummer(this.kontonummer) + " - " + this.kontoTyp + " von " + this.name + ": Zinssatz: " + this.zinssatz + "%, Kontostand: " + this.kontostand; + } +} diff --git a/src/UE01_030924_Wiederholung/Konto.java b/src/UE01_030924_Wiederholung/Konto.java new file mode 100644 index 0000000..3859be4 --- /dev/null +++ b/src/UE01_030924_Wiederholung/Konto.java @@ -0,0 +1,62 @@ +package UE01_030924_Wiederholung; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; + +public abstract class Konto { + private static int kontonummerCounter = 0; + protected int kontonummer; + protected double kontostand; + protected double zinssatz; + protected ArrayList buchungsvorgaenge = new ArrayList<>(); + String kontoTyp; + + public Konto(double betrag, double zinssatz, String typ) { + if (kontonummerCounter >= 999999) throw new RuntimeException("Zu viele Konten"); + this.kontostand = betrag; + this.zinssatz = zinssatz; + this.kontonummer = ++kontonummerCounter; + this.kontoTyp = typ; + this.buchungsvorgaenge.add("Kontoeröffnung: Betrag = " + this.kontostand + ", Zinssatz = " + this.zinssatz + "%"); + } + + public Konto(double zinssatz, String typ) { + if (kontonummerCounter >= 999999) throw new RuntimeException("Zu viele Konten"); + this.kontostand = 0; + this.zinssatz = zinssatz; + this.kontonummer = ++kontonummerCounter; + this.kontoTyp = typ; + this.buchungsvorgaenge.add("Kontoeröffnung: Betrag = " + this.kontostand + ", Zinssatz = " + this.zinssatz + "%"); + } + + @Override + public String toString() { + return kontonummer(this.kontonummer) + " - " + this.kontoTyp + ": Zinssatz: " + this.zinssatz + "%, Kontostand: " + this.kontostand; + } + + public void verrechneZinsen() { + double zins = this.kontostand * (this.zinssatz / 100); + this.buchungsvorgaenge.add("Zinsen verrechnet: " + zins); + this.kontostand += zins; + } + + public void speichereKontoauszug() { + try { + Files.write(Paths.get("src/UE01_030924_Wiederholung/auszuege/auszug" + kontonummer(this.kontonummer) + ".txt"), this.buchungsvorgaenge); + } catch (IOException e) { + e.getStackTrace(); + } + } + + public String kontonummer(int kontonummer) { + return ("000000" + kontonummer).substring(("000000" + kontonummer).length() - 6); + } + + public abstract double einzahlung(double betrag); + + public double getKontostand() { + return this.kontostand; + } +} diff --git a/src/UE01_030924_Wiederholung/Kreditkonto.java b/src/UE01_030924_Wiederholung/Kreditkonto.java new file mode 100644 index 0000000..67f896f --- /dev/null +++ b/src/UE01_030924_Wiederholung/Kreditkonto.java @@ -0,0 +1,28 @@ +package UE01_030924_Wiederholung; + +public class Kreditkonto extends Konto { + String name = "undefined"; + + public Kreditkonto(String name, double zinssatz, double betrag) { + super((betrag < 0 ? betrag : betrag * -1), zinssatz, "Kreditkonto"); + if (name != null) this.name = name; + } + + public double einzahlung(double betrag) { + if (betrag < 0) return 0; + double overflow = this.kontostand; + this.kontostand += betrag; + if (this.kontostand > 0) { + this.kontostand = 0; + this.buchungsvorgaenge.add("Einzahlung: " + (-overflow)); + return Math.abs(overflow); + } + this.buchungsvorgaenge.add("Einzahlung: " + betrag); + return betrag; + } + + @Override + public String toString() { + return kontonummer(this.kontonummer) + " - " + this.kontoTyp + " von " + this.name + ": Zinssatz: " + this.zinssatz + "%, Kontostand: " + this.kontostand; + } +} \ No newline at end of file diff --git a/src/UE01_030924_Wiederholung/SEW3 UE01 2024 WdhPrfg.pdf b/src/UE01_030924_Wiederholung/SEW3 UE01 2024 WdhPrfg.pdf new file mode 100644 index 0000000..d8ddf6d Binary files /dev/null and b/src/UE01_030924_Wiederholung/SEW3 UE01 2024 WdhPrfg.pdf differ diff --git a/src/UE01_030924_Wiederholung/Sparbuch.java b/src/UE01_030924_Wiederholung/Sparbuch.java new file mode 100644 index 0000000..8f3fe14 --- /dev/null +++ b/src/UE01_030924_Wiederholung/Sparbuch.java @@ -0,0 +1,25 @@ +package UE01_030924_Wiederholung; + +public class Sparbuch extends Konto { + public Sparbuch(double betrag, double zinssatz) { + super(betrag, zinssatz, "Sparbuch"); + } + + public Sparbuch(double zinssatz) { + super(zinssatz, "Sparbuch"); + } + + public double einzahlung(double betrag) { + if (betrag < 0) return 0; + this.kontostand += betrag; + this.buchungsvorgaenge.add("Einzahlung: " + betrag); + return betrag; + } + + public boolean auszahlung(double betrag) { + if (this.kontostand - betrag < 0) return false; + this.kontostand -= betrag; + this.buchungsvorgaenge.add("Auszahlung: " + betrag); + return true; + } +} diff --git a/src/UE02_100924_Collections_TreeSet/Buch.java b/src/UE02_100924_Collections_TreeSet/Buch.java new file mode 100644 index 0000000..141a72c --- /dev/null +++ b/src/UE02_100924_Collections_TreeSet/Buch.java @@ -0,0 +1,26 @@ +package UE02_100924_Collections_TreeSet; + +public class Buch implements Comparable { + String title; + String autor; + int price; + + public Buch(String title, String autor, int price) { + this.title = title; + this.autor = autor; + this.price = price; + } + + @Override + public String toString() { + return "Buch{" + "title='" + title + '\'' + ", autor='" + autor + '\'' + ", price=" + price + '}'; + } + + @Override + public int compareTo(Buch o) { + if (this.price != o.price) return Integer.compare(this.price, o.price); + int compare = this.title.compareTo(o.title); + if (compare != 0) return compare; + return this.autor.compareTo(o.autor); + } +} diff --git a/src/UE02_100924_Collections_TreeSet/Person.java b/src/UE02_100924_Collections_TreeSet/Person.java new file mode 100644 index 0000000..ecf32e9 --- /dev/null +++ b/src/UE02_100924_Collections_TreeSet/Person.java @@ -0,0 +1,23 @@ +package UE02_100924_Collections_TreeSet; + +public class Person implements Comparable { + public String vorname; + public String famname; + + public Person(String vn, String fn) { + this.vorname = vn.trim(); + this.famname = fn.trim(); + } + + @Override + public String toString() { + return "Person{" + "vorname='" + vorname + '\'' + ", famname='" + famname + '\'' + '}'; + } + + @Override + public int compareTo(Person o) { + int compare = this.famname.compareToIgnoreCase(o.famname); + if (compare != 0) return compare; + return this.vorname.compareToIgnoreCase(o.vorname); + } +} diff --git a/src/UE02_100924_Collections_TreeSet/Punkt.java b/src/UE02_100924_Collections_TreeSet/Punkt.java new file mode 100644 index 0000000..0908ecc --- /dev/null +++ b/src/UE02_100924_Collections_TreeSet/Punkt.java @@ -0,0 +1,26 @@ +package UE02_100924_Collections_TreeSet; + +public class Punkt implements Comparable { + int pointX; + int pointY; + + public Punkt(int x, int y) { + this.pointX = x; + this.pointY = y; + } + + @Override + public String toString() { + return "(" + pointX + "|" + pointY + ")"; + } + + @Override + public int compareTo(Punkt o) { + //Origin of the Sorting of the Points is the left lower corner. + double vector = Math.sqrt(this.pointX * this.pointX + this.pointY * this.pointY); + double objectVector = Math.sqrt(o.pointX * o.pointX + o.pointY * o.pointY); + if (vector != objectVector) return Double.compare(vector, objectVector); + if (this.pointX != o.pointX) return Integer.compare(this.pointX, o.pointX); + return Integer.compare(this.pointY, o.pointY); + } +} diff --git a/src/UE02_100924_Collections_TreeSet/SEW3 UE02 2024 TreeSet.pdf b/src/UE02_100924_Collections_TreeSet/SEW3 UE02 2024 TreeSet.pdf new file mode 100644 index 0000000..e92afea Binary files /dev/null and b/src/UE02_100924_Collections_TreeSet/SEW3 UE02 2024 TreeSet.pdf differ diff --git a/src/UE02_100924_Collections_TreeSet/UE02_Main.java b/src/UE02_100924_Collections_TreeSet/UE02_Main.java new file mode 100644 index 0000000..8207c3d --- /dev/null +++ b/src/UE02_100924_Collections_TreeSet/UE02_Main.java @@ -0,0 +1,67 @@ +package UE02_100924_Collections_TreeSet; + +import java.util.Comparator; +import java.util.Set; +import java.util.TreeSet; + +public class UE02_Main { + + public static void main(String[] args) { + testPerson(); + testPunkt(); + testBuch(); + } + + public static void testPerson() { +// Comparator personComp = (o1, o2) -> { +// int compare = o1.famname.compareToIgnoreCase(o2.famname); +// if (compare != 0) return compare; +// return o1.vorname.compareToIgnoreCase(o2.vorname); +// }; +// Set persons = new TreeSet<>(personComp); + + Set persons = new TreeSet<>(); + + persons.add(new Person("Tom", "Human")); + persons.add(new Person("Benton", "Mensch")); + persons.add(new Person("Anton", "Mensch")); + persons.add(new Person("Anton", "Mensch")); + + System.out.println(persons); + } + + public static void testPunkt() { + Set points = new TreeSet<>(); + + points.add(new Punkt(1, 1)); + points.add(new Punkt(3, 3)); + points.add(new Punkt(4, 4)); + points.add(new Punkt(-1, -1)); + points.add(new Punkt(1, -1)); + points.add(new Punkt(-1, 1)); + System.out.println(points); + } + + public static void testBuch() { + Set books = new TreeSet<>(); + + books.add(new Buch("Book", "AntonZ", 10)); + books.add(new Buch("Book", "Anton", 10)); + books.add(new Buch("Anaconda", "Anton", 10)); + books.add(new Buch("Book", "Tom", 40)); + books.add(new Buch("Book", "Tom", 10)); + books.add(new Buch("Book", "Tom", 20)); + books.add(new Buch("Book", "Tom", 10)); + books.add(new Buch("Book", "Tom", 10)); + + System.out.println(books); + + Comparator buchComp = (o1, o2) -> { + if (!o1.title.equals(o2.title)) return o1.title.compareToIgnoreCase(o2.title); + if (!o1.autor.equals(o2.autor)) return o1.autor.compareToIgnoreCase(o2.autor); + return Integer.compare(o1.price, o2.price); + }; + Set compBooks = new TreeSet<>(buchComp); + System.out.println(compBooks); + } +} diff --git a/src/UE02_100924_Collections_TreeSet/theorie/Mensch.java b/src/UE02_100924_Collections_TreeSet/theorie/Mensch.java new file mode 100644 index 0000000..4ad32d5 --- /dev/null +++ b/src/UE02_100924_Collections_TreeSet/theorie/Mensch.java @@ -0,0 +1,41 @@ +package UE02_100924_Collections_TreeSet.theorie; + +public class Mensch { + String vor; + String nach; + int alter; + + public Mensch(String vor, String nach, int alter) { + this.vor = vor; + this.nach = nach; + this.alter = alter; + } + + @Override + public String toString() { + return "Mensch{" + + "vor='" + vor + '\'' + + ", nach='" + nach + '\'' + + ", alter=" + alter + + '}'; + } + + + public int compareToXXXX(Mensch o) { + //liefert : positive Zahl, wenn this größer als o + // negative Zahl, wenn this kleiner als o + // 0 , wenn beide gleich + // erstes Kriterium: Vorname + int vergleich = this.vor.compareTo(o.vor); + if (vergleich != 0) + return vergleich; + + //zweites Kriterium: Nachname + vergleich = this.nach.compareTo(o.nach); + if (vergleich != 0) + return vergleich; + + vergleich = this.alter-o.alter; + return vergleich; + } +} diff --git a/src/UE02_100924_Collections_TreeSet/theorie/Set_Main.java b/src/UE02_100924_Collections_TreeSet/theorie/Set_Main.java new file mode 100644 index 0000000..905ed6d --- /dev/null +++ b/src/UE02_100924_Collections_TreeSet/theorie/Set_Main.java @@ -0,0 +1,57 @@ +package UE02_100924_Collections_TreeSet.theorie; + +import java.util.*; + +public class Set_Main { + public static void main(String[] args) { + List names1 = new ArrayList<>(); + + names1.add("Karl"); + names1.add("Karl"); + names1.add("Karl"); + names1.add("Karl"); + names1.add("Franz"); + + System.out.println(names1); + + //Ein Set verhindert Duplikate + //TreeSet sortiert Einträge nach ihrer natürlichen Ordnung + Set names2 = new TreeSet<>(names1); + //names2.addAll(names1); + System.out.println(names2); + + //Zugriff auf Elemente - kein Index + names2.remove("Otto"); + System.out.println(names2); + for (String s:names2) { + System.out.println(s.hashCode()); + } + Comparator mComp = new Comparator() { + @Override + public int compare(Mensch o1, Mensch o2) { + int vergleich = o1.vor.compareTo(o2.vor); + if (vergleich != 0) + return vergleich; + + //zweites Kriterium: Nachname + vergleich = o1.nach.compareTo(o2.nach); + if (vergleich != 0) + return vergleich; + + vergleich = o1.alter-o2.alter; + return vergleich; + } + }; + + Set people = new TreeSet<>(mComp); + + people.add(new Mensch("Max","Mustermann", 22)); + people.add(new Mensch("Max","Mustermann", 23)); + people.add(new Mensch("Christian","Klein", 99)); + + System.out.println(people); + + + + } +} diff --git a/src/UE03_170924_Map_Birthdays/Birthday.java b/src/UE03_170924_Map_Birthdays/Birthday.java new file mode 100644 index 0000000..8de356b --- /dev/null +++ b/src/UE03_170924_Map_Birthdays/Birthday.java @@ -0,0 +1,44 @@ +package UE03_170924_Map_Birthdays; + +public class Birthday implements Comparable { + private int day; + private int month; + private int year; + + public Birthday(String date) { + if (date.length() != 10) return; + for (int i = 0; i < 10; i++) { + if ((i == 2 || i == 5) && date.charAt(i) == '.') continue; + if (Character.isDigit(date.charAt(i))) continue; + return; + } + this.day = Integer.parseInt(date.substring(0, 2)); + this.month = Integer.parseInt(date.substring(3, 5)); + this.year = Integer.parseInt(date.substring(6, 10)); + } + + public int getYear() { + return year; + } + + public int getMonth() { + return month; + } + + public int getDay() { + return day; + } + + @Override + public String toString() { + return "Birthday{" + "day=" + day + ", month=" + month + ", year=" + year + '}'; + } + + @Override + public int compareTo(Object object) { + Birthday o = (Birthday) object; + if (this.day != o.getDay()) return Integer.compare(this.day, o.getDay()); + if (this.month != o.getMonth()) return Integer.compare(this.month, o.getMonth()); + return Integer.compare(this.year, o.getYear()); + } +} diff --git a/src/UE03_170924_Map_Birthdays/BirthdayDatamining.java b/src/UE03_170924_Map_Birthdays/BirthdayDatamining.java new file mode 100644 index 0000000..5d289eb --- /dev/null +++ b/src/UE03_170924_Map_Birthdays/BirthdayDatamining.java @@ -0,0 +1,145 @@ +package UE03_170924_Map_Birthdays; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.time.LocalDate; +import java.util.*; + +public class BirthdayDatamining { + List birthdays; + + public BirthdayDatamining(Path datei) { + if (datei == null) return; + List tempBirthdays = new ArrayList<>(); + try { + for (String line : Files.readAllLines(datei)) { + while (line.length() >= 11) { + tempBirthdays.add(new Birthday(line.substring(0, 10))); + if (line.length() > 11) line = line.substring(11); + if (line.length() == 10) tempBirthdays.add(new Birthday(line.substring(0, 10))); + } + } + } catch (IOException e) { + return; + } + birthdays = new ArrayList<>(tempBirthdays); + } + + public static String formatedDate(int date) { + return date < 10 ? "0" + date : String.valueOf(date); + } + + public double arithmeticMiddle() { + double output = 0; + for (Birthday birthday : birthdays) output += birthday.getYear(); + return output / birthdays.size(); + } + + public int mostCommonYear() { + int mostCommonYear = 0; + int counter = 0; + Map statistic = new HashMap<>(); + for (Birthday birthday : birthdays) + statistic.put(birthday.getYear(), statistic.getOrDefault(birthday.getYear(), 0) + 1); +// int happen = 0; + for (Map.Entry entry : statistic.entrySet()) + if (entry.getValue() > counter) { + counter = entry.getValue(); + mostCommonYear = entry.getKey(); +// happen = counter; + } +// System.out.println(happen); + return mostCommonYear; + } + + public Map birthdaysPerMonth() { + Map statistic = new TreeMap<>(); + for (Birthday birthday : birthdays) + statistic.put(birthday.getMonth(), statistic.getOrDefault(birthday.getMonth(), 0) + 1); + return statistic; + } + + public int birthdaysOnDate(int day, int month) { + int counter = 0; + for (Birthday birthday : birthdays) + if (birthday.getDay() == day && birthday.getMonth() == month) counter++; + return counter; + } + + public int leapYear() { + int counter = 0; + for (Birthday birthday : birthdays) + if ((birthday.getYear() % 4 == 0 && birthday.getYear() % 100 != 0) || (birthday.getYear() % 400 == 0)) + counter++; + return counter; + } + + public Birthday youngestBirthday() { + LocalDate latestDate = LocalDate.MIN; + for (Birthday birthday : birthdays) { + LocalDate currentDate; + try { + currentDate = LocalDate.of(birthday.getYear(), birthday.getMonth(), birthday.getDay()); + } catch (Exception e) { + System.out.println("Fehlerhaftes Datum."); + return new Birthday("00.00.0000"); + } + if (currentDate.isAfter(latestDate)) latestDate = currentDate; + } + return new Birthday(formatedDate(latestDate.getDayOfMonth()) + '.' + formatedDate(latestDate.getMonthValue()) + '.' + latestDate.getYear()); + } + + public Birthday oldestBirthday() { + LocalDate latestDate = LocalDate.MAX; + for (Birthday birthday : birthdays) { + LocalDate currentDate; + try { + currentDate = LocalDate.of(birthday.getYear(), birthday.getMonth(), birthday.getDay()); + } catch (Exception e) { + System.out.println("Fehlerhaftes Datum."); + return new Birthday("00.00.0000"); + } + if (currentDate.isBefore(latestDate)) latestDate = currentDate; + } + return new Birthday(formatedDate(latestDate.getDayOfMonth()) + '.' + formatedDate(latestDate.getMonthValue()) + '.' + latestDate.getYear()); + } + + public int youngestTeacherYear() { + Set birthdayYear = new TreeSet<>(); + for (Birthday birthday : birthdays) birthdayYear.add(birthday.getYear()); + List years = new ArrayList<>(birthdayYear); + for (int i = 1; i < years.size(); i++) + if (years.get(i - 1) + 4 <= years.get(i)) return years.get(i - 1); + return 0; + } + + public int howManyTeacher() { + int output = 0; + for (Birthday birthday : birthdays) if (birthday.getYear() <= youngestTeacherYear()) output++; + return output; + } + + public List teacherList() { + List teacherList = new ArrayList<>(); + for (Birthday birthday : birthdays) if (birthday.getYear() <= youngestTeacherYear()) teacherList.add(birthday); + return teacherList; + } + + public List studentList() { + List studentList = new ArrayList<>(); + for (Birthday birthday : birthdays) if (birthday.getYear() > youngestTeacherYear()) studentList.add(birthday); + return studentList; + } + + public int sameBirthday() { + Map birthdayCounter = new TreeMap<>(); + for (Birthday birthday : birthdays) { + Birthday date = new Birthday(formatedDate(birthday.getDay()) + "." + formatedDate(birthday.getMonth()) + ".2000"); + birthdayCounter.put(date, birthdayCounter.getOrDefault(date, 0) + 1); + } +// for (Map.Entry entry : birthdayCounter.entrySet()) if (entry.getValue() > 1) counter += entry.getValue(); +// return counter; + return birthdayCounter.values().stream().filter(v -> v > 1).mapToInt(Integer::intValue).sum(); //Alternative (erstellt von ChatGPT) original darüber. + } +} \ No newline at end of file diff --git a/src/UE03_170924_Map_Birthdays/SEW3 UE03 2024 Map_Birthdays.pdf b/src/UE03_170924_Map_Birthdays/SEW3 UE03 2024 Map_Birthdays.pdf new file mode 100644 index 0000000..4f0a987 Binary files /dev/null and b/src/UE03_170924_Map_Birthdays/SEW3 UE03 2024 Map_Birthdays.pdf differ diff --git a/src/UE03_170924_Map_Birthdays/UE03_Birthdays.java b/src/UE03_170924_Map_Birthdays/UE03_Birthdays.java new file mode 100644 index 0000000..aadc46e --- /dev/null +++ b/src/UE03_170924_Map_Birthdays/UE03_Birthdays.java @@ -0,0 +1,64 @@ +package UE03_170924_Map_Birthdays; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +public class UE03_Birthdays { + public static void main(String[] args) { + Path datei = Path.of("src/UE03_170924_Map_Birthdays/birthdays.txt"); + BirthdayDatamining birthdayDatamining = new BirthdayDatamining(datei); + System.out.println("In \"HelloWorld!2\" sind folgende Zeichen" + new HashMap<>(zeichenStatistik("HelloWorld!2"))); + System.out.println("In der Datei \"birthdays.txt\" sind folgende Zeichen" + new HashMap<>(zeichenStatistik(datei))); + testBirthday(); + System.out.println("Der Mittelwert ist: " + birthdayDatamining.arithmeticMiddle()); + System.out.println("Das häufigste Jahr ist: " + birthdayDatamining.mostCommonYear()); + System.out.println("Anzahl Geburtstage pro Monat" + birthdayDatamining.birthdaysPerMonth()); + System.out.println("Am 22. Mai haben " + birthdayDatamining.birthdaysOnDate(22, 5) + " Geburtstag"); + System.out.println("Am 24. Dezember haben " + birthdayDatamining.birthdaysOnDate(24, 12) + " Geburtstag"); + System.out.println("In einem Schaltjahr geboren: " + birthdayDatamining.leapYear()); + System.out.println("Der Jüngste hat Geburtstag am: " + birthdayDatamining.youngestBirthday()); + System.out.println("Der Älteste hat Geburtstag am: " + birthdayDatamining.oldestBirthday()); + System.out.println("Geburtstag des jüngsten Lehrers: " + birthdayDatamining.youngestTeacherYear()); + System.out.println("Es gibt " + birthdayDatamining.howManyTeacher() + " Lehrer"); + System.out.println("Der erste und Letzte Lehrer-Geburtstag ist: " + birthdayDatamining.teacherList().getFirst() + ", " + birthdayDatamining.teacherList().getLast()); + System.out.println("Der erste und Letzte Schüler-Geburtstag ist: " + birthdayDatamining.studentList().getFirst() + ", " + birthdayDatamining.studentList().getLast()); + System.out.println("Anzahl der Personen die sich einen Geburtstag teilen: " + birthdayDatamining.sameBirthday()); + } + + public static Map zeichenStatistik(String text) { + if (text == null) return new HashMap<>(); + Map statistic = new HashMap<>(); + for (char letter : text.toCharArray()) statistic.put(letter, statistic.getOrDefault(letter, 0.0) + 1); + return statistic; + } + + public static Map zeichenStatistik(Path datei) { + if (datei == null) return new HashMap<>(); + Map statistic = new HashMap<>(); + try { + for (String line : Files.readAllLines(datei)) + for (char letter : line.toCharArray()) statistic.put(letter, statistic.getOrDefault(letter, 0.0) + 1); + } catch (IOException e) { + return new HashMap<>(); + } + return statistic; + } + + public static void testBirthday() { + Set test = new TreeSet<>(); + Birthday test0 = new Birthday("01.02.3000"); + Birthday test1 = new Birthday("02.02.3000"); + Birthday test2 = new Birthday("02.02.3000"); + Birthday test3 = new Birthday("01.02.4000"); + test.add(test0); + test.add(test1); + test.add(test2); + test.add(test3); + System.out.println("Test von Sortieren: " + test); + } +} diff --git a/src/UE03_170924_Map_Birthdays/birthdays.txt b/src/UE03_170924_Map_Birthdays/birthdays.txt new file mode 100644 index 0000000..e44098a --- /dev/null +++ b/src/UE03_170924_Map_Birthdays/birthdays.txt @@ -0,0 +1,162 @@ +05.07.1997,07.05.1999,11.10.1998,25.08.1999,04.05.1996,03.06.1993,28.01.1997,27.09.1997 +28.07.1999,27.12.1997,14.04.1998,31.05.1961,19.12.1997,04.05.1995,15.03.1996,27.01.1997 +21.04.1996,19.11.1996,04.07.1974,29.05.1995,01.10.1998,25.07.1996,11.05.1995,26.01.1998 +14.04.1995,13.05.1996,30.05.1995,18.04.1995,19.06.1996,18.08.1998,20.04.1998,09.05.1997 +09.08.1994,21.04.1996,12.10.1998,13.09.1994,25.05.1993,14.10.1996,16.01.1998,11.05.1998 +25.01.1995,23.10.1995,27.12.1993,30.07.1997,04.02.1996,07.05.1998,20.10.1995,01.05.1996 +28.05.1999,13.11.1994,25.11.1996,10.02.1997,30.10.1998,07.04.1998,05.12.1952,29.08.1996 +18.07.1995,01.10.1997,25.04.1994,11.01.1997,23.04.1997,31.07.1999,18.02.1998,05.11.1998 +17.02.1978,07.01.1999,25.11.1996,03.04.1999,30.01.1997,13.01.1998,30.04.1999,04.11.1997 +22.12.1998,11.09.1992,18.01.1997,02.09.1996,01.04.1998,18.02.1999,08.04.1999,19.09.1996 +28.03.1999,17.05.1998,26.12.1995,03.03.1971,05.04.1995,07.05.1996,31.07.1997,22.10.1995 +01.07.1998,14.01.1995,15.06.1996,11.07.1966,05.08.1999,17.01.1997,27.01.1996,15.06.1998 +18.09.1996,30.10.1995,09.09.1998,15.06.1997,08.07.1963,25.12.1994,26.08.1995,14.08.1995 +21.01.1996,25.05.1996,22.08.1995,05.03.1995,16.01.1995,19.10.1965,03.08.1999,15.01.1995 +12.04.1996,23.02.1997,19.08.1998,26.11.1994,26.10.1997,09.05.1994,10.10.1993,28.07.1997 +10.05.1995,24.05.1995,27.11.1996,25.11.1997,29.11.1998,19.12.1997,04.07.1967,03.11.1998 +12.11.1998,07.11.1997,03.09.1994,15.04.1996,12.04.1996,06.01.1995,14.05.1998,14.10.1994 +20.01.1999,10.02.1995,30.01.1998,06.02.1996,04.04.1998,26.12.1994,11.02.1996,06.05.1998 +01.05.1997,17.08.1997,14.10.1994,06.03.1968,25.02.1998,11.05.1994,11.05.1999,11.02.1998 +02.06.1995,12.04.1997,28.10.1998,02.09.1998,19.03.1998,29.07.1998,31.10.1996,08.05.1999 +24.08.1998,29.01.1999,22.03.1999,20.06.1997,04.10.1994,20.02.1997,11.05.1998,09.05.1996 +17.03.1999,26.01.1995,07.09.1996,25.08.1997,14.02.1996,29.05.1999,27.11.1998,18.06.1995 +17.06.1995,26.01.1998,03.01.1999,23.09.1996,16.10.1996,12.02.1996,23.07.1999,22.04.1996 +19.12.1998,14.05.1995,18.12.1997,06.06.1994,11.04.1996,06.05.1999,28.12.1998,28.03.1997 +05.02.1999,28.12.1995,18.05.1994,03.03.1996,21.10.1996,26.02.1997,01.10.1997,21.12.1996 +24.02.1996,17.02.1999,06.03.1996,16.09.1995,27.04.1999,27.04.1997,03.03.1999,31.01.1999 +13.08.1996,17.02.1974,09.03.1996,01.04.1995,22.04.1996,16.12.1963,11.12.1998,03.02.1998 +13.03.1997,23.06.1997,09.08.1998,29.09.1996,08.07.1994,23.02.1997,24.08.1994,02.06.1998 +18.02.1998,07.03.1996,06.10.1998,27.12.1998,16.04.1995,28.01.1998,07.09.1998,15.05.1994 +27.07.1995,09.07.1999,18.06.1998,24.04.1998,29.04.1997,25.01.1998,14.09.1997,04.11.1996 +24.07.1991,20.08.1997,01.04.1995,02.10.1994,10.04.1999,16.02.1996,23.01.1951,05.04.1999 +13.02.1998,25.05.1952,04.04.1998,13.11.1970,18.11.1967,21.10.1995,04.10.1996,29.04.1999 +09.05.1998,03.01.1998,10.08.1995,16.12.1995,21.02.1999,16.08.1997,18.09.1994,18.05.1997 +31.10.1995,07.07.1995,14.07.1997,03.05.1997,02.01.1995,23.10.1995,01.06.1995,21.10.1997 +14.03.1997,13.11.1997,31.12.1995,20.10.1996,30.04.1998,15.11.1995,18.03.1998,20.12.1996 +30.03.1994,20.09.1997,10.04.1997,24.06.1997,11.05.1999,30.03.1994,30.03.1996,04.07.1994 +20.07.1996,18.11.1996,04.12.1996,04.03.1996,17.12.1997,02.02.1996,10.05.1963,04.06.1968 +30.11.1998,19.08.1996,14.09.1998,24.11.1998,03.12.1997,19.09.1997,13.01.1998,29.12.1997 +13.12.1994,16.09.1997,24.04.1998,06.02.1999,14.03.1950,08.09.1994,24.10.1978,24.12.1998 +01.11.1996,26.02.1996,07.08.1997,02.08.1996,27.05.1995,28.06.1999,24.09.1998,06.10.1987 +27.11.1995,20.05.1997,29.05.1998,26.10.1979,24.03.1998,29.10.1995,25.09.1995,22.08.1996 +18.05.1995,05.04.1995,28.01.1999,06.09.1997,12.02.1995,09.05.1995,29.06.1999,26.09.1951 +22.11.1997,05.09.1996,29.01.1996,12.01.1995,28.02.1999,22.12.1997,13.05.1997,13.02.1997 +09.06.1998,23.05.1999,18.04.1997,02.08.1956,27.02.1997,18.04.1973,30.12.1997,01.01.1998 +23.11.1957,17.01.1998,14.03.1999,28.04.1995,19.10.1998,13.03.1995,30.09.1997,19.08.1998 +15.11.1996,04.08.1969,12.08.1998,03.07.1997,11.06.1958,24.05.1995,19.05.1963,22.06.1999 +22.07.1999,20.02.1996,23.10.1996,18.08.1975,30.06.1994,26.01.1996,25.11.1998,21.09.1996 +31.12.1996,02.10.1995,20.01.1997,21.10.1997,16.02.1995,24.08.1994,18.01.1998,27.11.1996 +01.05.1996,25.07.1966,30.10.1997,10.03.1999,26.11.1997,21.08.1997,26.06.1999,27.12.1993 +02.09.1997,21.12.1994,14.12.1995,18.06.1999,21.07.1997,06.12.1981,02.08.1955,28.07.1998 +29.10.1997,20.04.1998,14.02.1997,08.05.1998,15.10.1996,22.08.1997,24.04.1992,16.04.1999 +23.01.1995,06.11.1998,22.11.1995,28.01.1997,17.09.1999,07.10.1998,08.05.1996,23.09.1992 +21.06.1996,02.07.1994,05.09.1995,09.03.1996,08.04.1995,27.06.1996,22.05.1966,11.09.1997 +01.02.1999,22.08.1998,21.05.1993,13.02.1998,22.02.1999,19.09.1996,09.02.1998,30.07.1996 +21.03.1999,04.09.1994,19.12.1995,21.04.1999,27.01.1996,23.01.1998,26.09.1998,31.05.1995 +22.05.1999,13.06.1997,16.04.1995,08.02.1996,04.04.1997,02.09.1996,27.01.1995,19.11.1996 +12.05.1994,04.04.1997,13.05.1996,12.08.1998,20.03.1957,04.01.1995,12.02.1998,05.06.1997 +12.01.1994,29.03.1999,16.02.1999,21.04.1998,19.11.1997,17.02.1996,27.05.1997,12.07.1997 +28.08.1996,20.02.1997,19.08.1996,19.06.1995,29.02.1996,22.02.1999,01.02.1997,17.01.1997 +16.11.1994,22.12.1994,12.10.1972,12.02.1998,29.04.1994,11.10.1995,18.04.1971,12.09.1997 +16.06.1999,03.07.1998,19.07.1994,16.07.1994,06.03.1995,20.04.1999,26.07.1999,29.06.1994 +07.04.1995,07.05.1997,16.06.1998,01.11.1977,11.05.1960,17.08.1998,30.09.1996,07.08.1998 +20.09.1995,23.04.1996,23.08.1996,01.11.1997,12.03.1999,09.01.1998,27.09.1997,21.08.1999 +30.07.1999,14.10.1996,01.01.1995,17.03.1981,18.11.1995,25.05.1999,22.12.1993,01.12.1995 +07.10.1998,20.10.1965,09.06.1995,13.05.1996,08.08.1996,29.02.1996,25.03.1997,07.11.1996 +12.12.1996,18.11.1997,26.09.1994,12.05.1998,19.12.1997,10.09.1997,14.08.1996,09.01.1997 +12.09.1962,08.07.1998,11.06.1997,16.03.1995,11.12.1996,29.04.1997,11.04.1996,07.01.1996 +21.05.1998,02.04.1997,12.08.1995,25.06.1996,31.01.1995,18.03.1999,25.02.1997,12.06.1993 +06.09.1997,04.10.1998,02.02.1967,04.10.1998,07.10.1998,29.09.1996,07.11.1994,15.01.1995 +21.08.1999,05.08.1999,07.10.1994,18.10.1999,05.07.1995,20.11.1998,01.08.1991,09.02.1997 +25.06.1996,05.11.1996,12.05.1999,06.03.1969,08.03.1996,21.05.1997,11.08.1995,09.06.1995 +12.07.1995,12.06.1997,20.02.1997,07.08.1996,25.03.1998,02.12.1994,18.04.1997,16.02.1995 +06.03.1999,21.12.1995,18.02.1998,13.10.1997,11.06.1997,04.11.1994,18.11.1995,31.10.1998 +06.06.1997,19.01.1996,25.06.1997,05.06.1998,13.02.1999,12.04.1999,04.02.1997,08.09.1998 +28.03.1995,08.07.1998,26.08.1996,01.11.1998,02.11.1993,19.03.1995,14.04.1998,06.10.1998 +19.05.1995,16.03.1998,17.09.1996,02.04.1996,23.07.1964,16.06.1994,16.02.1996,21.07.1964 +07.10.1994,01.11.1994,13.01.1999,08.11.1996,28.11.1996,02.06.1996,07.01.1999,11.02.1998 +20.02.1997,22.05.1999,18.01.1995,10.08.1999,10.02.1969,28.07.1997,22.06.1968,30.07.1993 +01.06.1997,24.01.1999,11.12.1997,09.06.1995,07.03.1997,08.06.1995,15.02.1997,04.05.1995 +03.11.1998,20.03.1997,17.04.1995,13.10.1997,08.03.1996,22.10.1995,14.09.1996,10.10.1972 +08.03.1999,15.07.1997,21.03.1995,20.01.1999,04.07.1998,08.02.1998,15.11.1998,05.01.1996 +14.02.1996,11.09.1996,25.04.1997,05.01.1999,22.04.1998,21.10.1995,09.09.1999,24.08.1999 +14.10.1996,05.05.1997,19.04.1996,28.03.1998,13.06.1995,15.10.1996,22.02.1999,14.03.1998 +05.02.1956,03.02.1998,13.11.1996,17.12.1996,01.08.1991,26.08.1998,21.02.1999,06.01.1999 +04.06.1997,01.12.1973,02.02.1997,06.11.1998,14.06.1995,26.05.1996,30.04.1996,23.01.1999 +19.09.1996,20.10.1960,11.11.1994,09.10.1954,01.08.1997,11.10.1964,23.01.1969,07.09.1964 +03.02.1998,20.07.1993,21.06.1951,07.12.1997,03.08.1998,23.03.1996,23.04.1963,09.05.1995 +11.03.1997,28.01.1998,21.09.1994,06.05.1999,03.05.1994,03.01.1996,14.09.1997,31.12.1994 +18.11.1963,12.03.1999,20.09.1998,16.11.1997,05.09.1996,08.08.1998,04.05.1996,13.08.1996 +14.12.1994,19.09.1996,16.08.1998,01.01.1998,14.11.1996,27.12.1996,20.06.1993,14.12.1997 +10.03.1995,20.12.1998,16.09.1998,14.11.1997,20.09.1997,12.05.1995,02.10.1995,07.10.1974 +05.12.1996,17.09.1994,20.07.1997,10.08.1998,25.10.1996,21.04.1996,22.09.1994,23.09.1994 +11.08.1996,05.10.1995,29.01.1995,05.09.1994,15.04.1999,04.07.1998,16.01.1996,24.10.1996 +31.07.1994,10.02.1996,08.06.1996,18.10.1998,30.06.1995,08.08.1996,19.02.1995,21.01.1998 +07.12.1998,11.01.1996,05.06.1994,23.10.1995,31.08.1997,30.05.1965,03.08.1999,29.06.1997 +16.12.1998,07.04.1995,22.10.1997,12.08.1997,13.09.1998,28.02.1965,17.12.1997,15.02.1998 +16.07.1994,23.08.1998,03.08.1995,24.10.1982,23.05.1998,07.12.1996,01.04.1998,25.12.1993 +15.01.1999,28.04.1998,04.02.1999,24.12.1997,14.07.1994,03.10.1994,08.02.1997,12.02.1994 +18.02.1994,01.12.1998,02.05.1996,27.11.1996,19.11.1994,27.01.1996,09.10.1998,14.12.1996 +26.08.1996,11.10.1970,07.06.1975,14.09.1997,12.07.1994,17.03.1995,06.12.1996,15.04.1996 +17.02.1972,03.03.1999,16.01.1997,16.04.1998,18.11.1993,25.09.1998,29.05.1998,03.06.1998 +27.03.1996,12.06.1994,07.09.1996,25.07.1997,04.04.1999,29.11.1995,06.09.1977,13.11.1998 +13.09.1997,14.08.1994,20.10.1996,10.10.1995,22.03.1996,14.09.1970,13.06.1996,20.04.1996 +09.11.1995,07.02.1996,15.12.1997,27.09.1998,26.01.1999,04.01.1996,13.05.1971,24.09.1997 +31.03.1999,22.06.1996,04.01.1997,02.03.1992,05.11.1994,03.05.1974,30.08.1978,04.03.1996 +21.10.1994,26.06.1998,26.12.1994,06.03.1999,01.01.1995,11.04.1974,10.07.1973,28.06.1997 +05.01.1995,09.04.1992,20.07.1995,28.03.1969,08.05.1999,25.11.1954,30.03.1998,05.03.1998 +29.08.1999,24.11.1995,02.11.1996,01.07.1996,09.11.1960,25.07.1996,22.04.1997,25.04.1995 +18.03.1996,19.07.1999,13.02.1996,11.01.1968,24.11.1995,08.07.1998,29.05.1996,22.08.1998 +09.07.1998,23.01.1998,22.04.1995,05.09.1997,16.04.1999,11.02.1997,15.09.1999,24.11.1995 +28.01.1995,17.05.1958,25.05.1999,28.02.1998,08.11.1995,18.11.1995,10.08.1995,23.04.1995 +05.12.1993,31.01.1998,06.05.1998,22.08.1997,06.05.1995,27.10.1962,10.06.1999,17.10.1997 +04.10.1996,17.10.1995,05.04.1997,02.10.1994,17.01.1997,16.08.1996,08.09.1997,08.01.1997 +23.05.1994,28.08.1996,21.11.1994,21.02.1995,11.02.1971,01.10.1997,17.05.1959,26.11.1997 +21.09.1999,16.11.1996,13.07.1996,05.08.1998,12.02.1999,30.10.1997,04.06.1996,10.08.1996 +07.09.1999,06.10.1994,06.08.1998,12.03.1997,09.10.1995,13.09.1980,25.08.1996,09.06.1997 +07.02.1996,11.01.1996,18.06.1998,28.10.1999,24.10.1994,19.06.1996,13.12.1995,16.10.1997 +20.02.1995,05.07.1996,16.12.1995,11.02.1998,08.01.1996,23.01.1997,02.11.1998,31.08.1995 +28.11.1996,26.11.1998,04.01.1996,10.03.1999,15.05.1995,16.10.1996,14.04.1969,06.05.1998 +27.12.1995,20.08.1994,06.08.1966,28.07.1995,09.09.1993,09.08.1995,14.05.1998,26.09.1997 +16.06.1953,28.05.1997,22.10.1998,15.07.1999,12.02.1997,09.07.1997,01.10.1997,02.09.1994 +13.08.1996,19.12.1996,21.03.1999,17.12.1994,03.08.1995,12.04.1997,06.08.1996,29.11.1998 +16.05.1959,23.10.1996,20.10.1993,21.01.1996,20.02.1995,21.08.1998,20.11.1995,24.02.1995 +30.07.1995,20.03.1996,16.03.1999,15.10.1997,12.11.1996,21.02.1997,08.01.1996,14.07.1964 +10.07.1997,14.08.1968,11.12.1997,09.10.1985,15.09.1980,08.04.1996,20.10.1995,01.01.1992 +22.06.1997,15.11.1997,11.11.1987,23.03.1999,06.06.1995,07.01.1997,11.02.1997,04.12.1996 +18.06.1999,19.02.1995,03.11.1999,18.08.1996,09.07.1998,31.01.1999,21.08.1999,02.10.1974 +23.11.1973,25.08.1998,22.01.1995,19.10.1998,06.03.1997,06.12.1997,15.09.1995,06.09.1998 +29.11.1994,09.05.1995,13.10.1998,03.08.1996,27.07.1975,11.01.1995,11.10.1995,11.01.1995 +17.05.1966,06.05.1996,18.09.1996,18.04.1998,29.10.1965,14.06.1996,24.01.1995,29.09.1995 +19.11.1996,31.10.1995,17.04.1998,08.09.1995,10.07.1993,17.08.1997,23.05.1996,11.12.1966 +26.11.1995,28.10.1996,11.10.1994,28.04.1996,24.12.1957,27.11.1998,12.12.1998,01.03.1999 +30.12.1997,17.06.1999,15.09.1998,05.02.1995,31.03.1999,18.10.1994,28.11.1994,09.01.1995 +03.07.1997,23.08.1996,07.07.1998,20.01.1998,12.06.1963,11.08.1994,01.10.1998,16.03.1966 +05.07.1997,15.10.1996,07.10.1994,04.06.1997,02.12.1963,28.12.1996,12.01.1997,01.04.1994 +04.02.1997,29.10.1998,12.03.1994,29.12.1996,26.09.1958,25.05.1995,09.08.1999,21.05.1999 +22.07.1996,13.08.1997,28.03.1996,18.09.1994,05.09.1996,28.09.1995,18.09.1997,08.08.1996 +18.11.1998,05.12.1997,09.07.1997,28.06.1995,14.05.1956,19.02.1996,17.04.1999,10.10.1997 +07.10.1995,17.09.1994,04.08.1996,08.04.1968,15.03.1996,24.02.1999,05.02.1995,16.01.1995 +02.10.1994,01.06.1999,04.09.1993,07.07.1998,06.12.1997,21.10.1985,17.11.1994,19.04.1982 +22.09.1996,09.12.1996,13.09.1995,14.07.1995,18.11.1997,09.10.1997,28.05.1961,11.09.1997 +21.02.1997,30.12.1998,20.12.1995,27.07.1996,30.07.1995,11.02.1997,03.05.1997,02.02.1997 +27.07.1999,14.01.1999,01.01.1999,17.06.1956,02.08.1997,11.09.1955,14.07.1993,20.10.1973 +16.05.1995,30.01.1999,25.05.1995,13.07.1999,16.12.1998,18.12.1997,12.08.1999,05.11.1996 +28.12.1998,20.11.1998,27.07.1997,18.01.1999,11.01.1999,02.09.1993,12.01.1999,09.08.1998 +05.06.1998,21.09.1997,01.12.1997,14.05.1998,04.05.1995,01.09.1998,23.01.1998,15.06.1968 +20.12.1998,17.12.1997,08.05.1961,28.12.1995,25.06.1997,21.11.1996,14.03.1992,19.04.1997 +20.03.1997,20.01.1999,03.04.1997,16.08.1998,09.04.1996,01.11.1998,30.08.1999,30.07.1997 +12.12.1998,06.07.1995,13.05.1997,05.07.1998,04.03.1996,27.06.1998,21.12.1994,12.02.1995 +14.06.1999,21.05.1997,16.05.1995,25.04.1998,28.08.1998,22.11.1969,17.06.1999,18.12.1996 +14.07.1997,08.09.1998,19.09.1995,05.09.1996,04.08.1997,15.10.1994,01.10.1968,12.03.1997 +21.06.1967,16.11.1994,11.07.1956,10.03.1999,02.04.1994,26.08.1996,01.10.1993,07.02.1997 +23.01.1996,04.09.1996,14.09.1998,20.09.1958,19.01.1996,12.01.1999,26.05.1999,03.09.1996 +16.02.1995,14.10.1994,14.03.1999,11.11.1995,19.04.1995,28.11.1997,29.03.1996,08.05.1996 +10.06.1955,05.01.1996,22.03.1996,04.07.1995,03.03.1997,08.03.1999,24.01.1971,07.11.1997 +05.03.1997,14.06.1973,20.12.1995,11.11.1995,04.05.1995,13.07.1995,10.07.1997,21.10.1996 +19.04.1997,09.09.1958,21.01.1997,17.12.1995,13.01.1995,25.12.1994,01.01.1999,01.09.1998 +15.08.1998,26.12.1994,24.04.1995,22.09.1997,04.06.1958,09.10.1995,05.06.1998,27.12.1997 +13.02.1996,30.12.1996,08.02.1996,18.02.1995,03.09.1998,11.12.1994,07.02.1997,17.05.1996 +16.02.1997,01.05.1996,02.03.1998,11.04.1996,19.01.1995,15.11.1994,07.07.1998,02.05.1998 +17.07.1998,10.05.1995,08.08.1995,18.06.1968,19.07.1997,15.12.1994,20.04.1958,24.01.1998 +25.08.1995,06.10.1995,12.05.1996,14.06.1996,01.02.1998,09.11.1998,19.12.1997,26.04.1995 \ No newline at end of file diff --git a/src/UE04_270924_Map_Cocktails/CocktailMix.txt b/src/UE04_270924_Map_Cocktails/CocktailMix.txt new file mode 100644 index 0000000..6b2c65f --- /dev/null +++ b/src/UE04_270924_Map_Cocktails/CocktailMix.txt @@ -0,0 +1,17 @@ +13 +ananas juice:Latin Lover,Carribean Dream,Malibu Barbados,Malibu Margarita +cachaca:Brazilian Sunrise,Latin Lover,Caipirinha,Caipifragola +carribean rum with coconut:Malibu Barbados,Malibu Margarita,Malibu Sunrise +cointreau:Margarita,Malibu Margarita +grenadine:Brazilian Sunrise,Tequila Sunrise,Carribean Dream,Malibu Sunrise +lemon juice:Brazilian Sunrise,Tequila Sunrise,Latin Lover,Carribean Dream,Malibu Margarita +lime juice:Latin Lover,Caipirinha,Caipifragola,Strawberry Daiquiri,Margarita,Malibu Margarita +orange juice:Brazilian Sunrise,Tequila Sunrise,Carribean Dream,Malibu Barbados,Malibu Sunrise +passion fruit nectar:Carribean Dream +rum:Strawberry Daiquiri,Carribean Dream +strawberry liqueur:Caipifragola,Strawberry Daiquiri +strawberry sirup:Caipifragola +tequila:Tequila Sunrise,Latin Lover,Margarita,Malibu Margarita +cachaca,lime juice,grenadine,lemon juice,orange juice,carribean rum with coconut + + diff --git a/src/UE04_270924_Map_Cocktails/SEW3 UE04 2024 Cocktails.pdf b/src/UE04_270924_Map_Cocktails/SEW3 UE04 2024 Cocktails.pdf new file mode 100644 index 0000000..dd9aec9 Binary files /dev/null and b/src/UE04_270924_Map_Cocktails/SEW3 UE04 2024 Cocktails.pdf differ diff --git a/src/UE04_270924_Map_Cocktails/UE04_Cocktails.java b/src/UE04_270924_Map_Cocktails/UE04_Cocktails.java new file mode 100644 index 0000000..cbdef16 --- /dev/null +++ b/src/UE04_270924_Map_Cocktails/UE04_Cocktails.java @@ -0,0 +1,37 @@ +package UE04_270924_Map_Cocktails; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.*; + +public class UE04_Cocktails { + public static void main(String[] args) { + System.out.println(readCocktails(Path.of("src/UE04_270924_Map_Cocktails/CocktailMix.txt"))); + } + + public static String readCocktails(Path path) { + Map> cocktails = new TreeMap<>(); + List lines; + try { + lines = Files.readAllLines(path); + } catch (IOException e) { + throw new RuntimeException(e); + } + if (lines.isEmpty()) throw new RuntimeException(); + lines.removeIf(String::isEmpty); + String existingIngredients = lines.getLast(); + lines.removeFirst(); + lines.removeLast(); + List output = new ArrayList<>(); + List ingredients = new ArrayList<>(List.of(existingIngredients.split(","))); + ingredients.replaceAll(String::trim); + //Set values = cocktails.getOrDefault(key.trim(), new TreeSet<>());values.add(line.split(":")[0].trim());cocktails.put(key.trim(), values); + for (String line : lines) + for (String key : line.split(":")[1].split(",")) + cocktails.computeIfAbsent(key.trim(), _ -> new TreeSet<>()).add(line.split(":")[0].trim()); //Alternative from ChatGPT (original above) + for (Map.Entry> entry : cocktails.entrySet()) + if (new HashSet<>(ingredients).containsAll(entry.getValue())) output.add(entry.getKey()); + return output.toString().substring(1, output.toString().length() - 1); + } +} \ No newline at end of file diff --git a/src/UE05_031024_RegExp1/Reguläre Ausdrücke.pdf b/src/UE05_031024_RegExp1/Reguläre Ausdrücke.pdf new file mode 100644 index 0000000..306c92c Binary files /dev/null and b/src/UE05_031024_RegExp1/Reguläre Ausdrücke.pdf differ diff --git a/src/UE05_031024_RegExp1/SEW3 UE05 2024 RegEx1.pdf b/src/UE05_031024_RegExp1/SEW3 UE05 2024 RegEx1.pdf new file mode 100644 index 0000000..7e636aa Binary files /dev/null and b/src/UE05_031024_RegExp1/SEW3 UE05 2024 RegEx1.pdf differ diff --git a/src/UE05_031024_RegExp1/UE05_Main.java b/src/UE05_031024_RegExp1/UE05_Main.java new file mode 100644 index 0000000..98e7306 --- /dev/null +++ b/src/UE05_031024_RegExp1/UE05_Main.java @@ -0,0 +1,87 @@ +package UE05_031024_RegExp1; + +import java.util.Arrays; +import java.util.regex.Pattern; + +public class UE05_Main { + static Pattern iPv4 = Pattern.compile("^(?:\\d{1,3}\\.){3}\\d{1,3}$"); + static Pattern iPv6 = Pattern.compile("^[a-fA-F\\d]{4}(?::[a-fA-F\\d]{4}){7}$"); + static Pattern macAddr = Pattern.compile("^(?:[a-fA-F\\d]{2}-){5}[a-fA-F\\d]{2}$"); + static Pattern classNames = Pattern.compile("^[A-Z]\\w*(?:\\.[A-Z]\\w*)*$"); + static Pattern flightNr = Pattern.compile("^[A-Z]{2,3}\\d{2,4}$"); + static Pattern floatNrs = Pattern.compile("^[+-]?\\d+(?:\\.?\\d+)?$"); + static Pattern dates = Pattern.compile("^\\d{1,2}\\.\\d{1,2}(?:\\.(?:\\d{2}|\\d{4}))?$"); + static Pattern emails = Pattern.compile("^[\\w-]*(?:\\.?[\\w-]+)*@[A-Za-z\\d-]{3,}\\.[A-Za-z]{2,}$"); + static Pattern kfzPlattes = Pattern.compile("^[A-Z]{2}-(?=.{4,5}$)[1-9]\\d*[A-NPR-Z][A-PR-Z]*$|^[A-Z]-(?=.{5,6}$)[1-9]\\d*[A-NPR-Z][A-PR-Z]*$"); + + public static void main(String[] args) { + testRegEx(); + System.out.println("\n"); + Arrays.stream(new String[]{"192.168.1.1", "255.255.255.255", "0.0.0.0", "256.100.50.25", "192.168.1.256", "192.168.-1.1", "192.168.1", "192.168.1.a", "123.456.78.90", "192.168.01.1"}).forEach(ip -> System.out.printf("IP-Adresse: %s -> %b%n", ip, isIPv4(ip))); + System.out.println("\n"); + Arrays.stream(new String[]{"00-1A-2B-3C-4D-5E", "00-1A-2B-3C-4D-5E", "00-1A-2B-3C-4D", "00-1A-2B-3C-4D-5E-6F", "G0-1A-2B-3C-4D-5E"}).forEach(mac -> System.out.printf("MAC-Adresse: %s -> %b%n", mac, isMacAddr(mac))); + System.out.println("\n"); + Arrays.stream(new String[]{"3.14", "-3.14", "+3.14", "0.0", "42", "-42", "+42", "3.", ".5", "3.14.15", "abc", "1e10", "2.5e3"}).forEach(dez -> System.out.printf("Dezimalzahl: %s -> %b%n", dez, isDezimal(dez))); + System.out.println("\n"); + Arrays.stream(new String[]{"7.11.2013", "7.11.13", "01.01.2020", "1.1.99", "31.12.2024", "31.02.2020", "32.01.2020", "7.11.201", "7.11", "7.13.2020", "abc.def.ghij"}).forEach(date -> System.out.printf("Datum: %s -> %b%n", date, isDate(date))); + System.out.println("\n"); + Arrays.stream(new String[]{"KI-1AAA", "KI-99ZZZ", "KI-10AA", "KI-999ZZ", "KI-100A", "KI-9999Z", "W-10AAA", "W-999ZZZ", "W-100AA", "W-9999ZZ", "W-1000A", "W-99999Z"}).forEach(platte -> System.out.printf("Kennzeichen: %s -> %b%n", platte, isKFZ_Kennzeichen(platte))); + } + + public static void testRegEx() { + System.out.println("\n" + + "01. IPv4: \t\t\t" + "192.168.12.0".matches(iPv4.pattern()) + "\n" + + "02. IPv4: \t\t\t" + "255.255.255.255".matches(iPv4.pattern()) + "\n\n" + + "01. IPv6: \t\t\t" + "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff".matches(iPv6.pattern()) + "\n" + + "02. IPv6: \t\t\t" + "abcd:ffff:1234:e5fc:12bf:5cf2:cabd:12cf".matches(iPv6.pattern()) + "\n\n" + + "01. MAC-Adress: \t" + "F1-CB-CF-E3-CA-45".matches(macAddr.pattern()) + "\n" + + "02. MAC-Adress: \t" + "FF-FF-FF-FF-FF-FF".matches(macAddr.pattern()) + "\n\n" + + "01. Class names: \t" + "Regex_Main".matches(classNames.pattern()) + "\n" + + "02. Class names: \t" + "Map.Entry".matches(classNames.pattern()) + "\n\n" + + "01. Flight Number: \t" + "AUS1234".matches(flightNr.pattern()) + "\n" + + "02. Flight Number: \t" + "SAS69".matches(flightNr.pattern()) + "\n\n" + + "01. Numbers: \t\t" + "3.1415926589".matches(floatNrs.pattern()) + "\n" + + "02. Numbers: \t\t" + String.format("%f", Math.E).matches(floatNrs.pattern()) + "\n" + + "03. Numbers: \t\t" + "235".matches(floatNrs.pattern()) + "\n\n" + + "01. Dates: \t\t\t" + "25.12.1969".matches(dates.pattern()) + "\n" + + "02. Dates: \t\t\t" + "11.12.07".matches(dates.pattern()) + "\n\n" + + "01. Emails: \t\t" + "mail@provider.com".matches(emails.pattern()) + "\n" + + "02. Emails: \t\t" + "sew@gmail.com".matches(emails.pattern()) + "\n\n" + + "01. Kennzeichen: \t" + "KI-1AAA".matches(kfzPlattes.pattern()) + "\n" + + "02. Kennzeichen: \t" + "KI-99ZZZ".matches(kfzPlattes.pattern()) + ); + } + + public static boolean isIPv4(String value) { + if (!value.matches(iPv4.pattern())) return false; + return Arrays.stream(value.split("\\.")).noneMatch(v -> Integer.parseInt(v) > 255); + } + + public static boolean isMacAddr(String value) { + return value.matches(macAddr.pattern()); + } + + public static boolean isDezimal(String value) { + return value.matches(floatNrs.pattern()); + } + + public static boolean isKFZ_Kennzeichen(String value) { + return value.matches(kfzPlattes.pattern()); + } + + public static boolean isDate(String value) { + if (!value.matches(dates.pattern())) return false; + String[] values = value.split("\\."); + return isValidDate(Integer.parseInt(values[0]), Integer.parseInt(values[1])); + } + + public static boolean isValidDate(int d, int m) { + return (m <= 12 && m >= 1) && (d >= 1 && d <= lastDayInMonth(m)); + } + + public static int lastDayInMonth(int m) { + if (m == 2) return 28; + else if (m == 4 || m == 6 || m == 9 || m == 11) return 30; + return 31; + } +} \ No newline at end of file diff --git a/src/UE06_151024_RegExp2/SEW3 UE06 2024 RegEx2.pdf b/src/UE06_151024_RegExp2/SEW3 UE06 2024 RegEx2.pdf new file mode 100644 index 0000000..fb852ed Binary files /dev/null and b/src/UE06_151024_RegExp2/SEW3 UE06 2024 RegEx2.pdf differ diff --git a/src/UE06_151024_RegExp2/UE06_Main.java b/src/UE06_151024_RegExp2/UE06_Main.java new file mode 100644 index 0000000..c1d9af8 --- /dev/null +++ b/src/UE06_151024_RegExp2/UE06_Main.java @@ -0,0 +1,103 @@ +package UE06_151024_RegExp2; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class UE06_Main { + public static void main(String[] args) { + Path htmlDatei = Path.of("src/UE06_151024_RegExp2/index.html"); + Path cssDatei = Path.of("src/UE06_151024_RegExp2/styles.css"); + System.out.println(tagStatistik(htmlDatei)); + System.out.println(links(htmlDatei)); + System.out.println(domains(htmlDatei)); + System.out.println(klassen(cssDatei)); + System.out.println(removeMultipleSpaces("Hallo Du kek !")); + System.out.println(bigStartingLetter("Hallo du kek !")); + System.out.println(lineSplitting("Es war einmal ein Lehrer namens Herr Klein, der in einem kleinen Dorf am Rande eines großen, dichten Waldes lebte. Aber Herr Klein war kein gewöhnlicher Lehrer. Während die meisten Lehrer Lesen, Schreiben und Rechnen unterrichteten, hatte Herr Klein eine ganz besondere Leidenschaft: das Programmieren. Seine Augen leuchteten jedes Mal auf, wenn er über Code sprach, und er konnte Stunden damit verbringen, knifflige Probleme zu lösen.\n" + "\n" + "Herr Klein war bekannt für seine Geduld und sein freundliches Wesen. Die Dorfbewohner liebten ihn, denn er brachte den Kindern bei, wie man Programme schreibt, die die Welt verbessern konnten. Die Kinder nannten ihn liebevoll \"den Magier des Codes\", denn er zauberte scheinbar mit Zahlen und Buchstaben, um unglaubliche Dinge zu erschaffen.\n" + "\n" + "Eines Tages hörte Herr Klein von einer alten Legende, die in seinem Dorf seit Generationen erzählt wurde. Tief im Herzen des Waldes sollte es einen magischen Code geben, den niemand je vollständig entschlüsselt hatte. Dieser Code, so hieß es, hatte die Macht, jede Frage der Welt zu beantworten, jedes Problem zu lösen und jede Vision wahr werden zu lassen. Doch er war verschlüsselt und versteckt in einer uralten Höhle, die nur denjenigen zugänglich war, die das Herz eines wahren Programmierers hatten.\n" + "\n" + "Fasziniert von dieser Legende beschloss Herr Klein, sich auf die Suche nach dem magischen Code zu machen. Er packte seinen Laptop, sein Lieblingsbuch über Algorithmen und machte sich auf den Weg in den dichten Wald. Der Weg war lang und voller Herausforderungen. Rätselhafte Pfade, die sich ständig veränderten, zwangen Herrn Klein dazu, seinen Verstand zu nutzen und clevere Algorithmen zu entwickeln, um die richtige Richtung zu finden. Manchmal musste er Code schreiben, um Brücken über tiefe Schluchten zu bauen oder wilde Tiere zu beruhigen, indem er für sie kleine Spiele programmierte.\n" + "\n" + "Nach vielen Tagen erreichte er endlich die alte Höhle. Ihre Wände waren mit uralten Runen bedeckt, die wie Programmzeilen wirkten. Herr Klein erkannte sofort, dass dies der magische Code war. Doch es war ein Rätsel, so komplex, dass es Jahrhunderte dauern würde, es von Hand zu lösen. Aber Herr Klein war nicht entmutigt. Er setzte sich hin, öffnete seinen Laptop und begann, den Code zu analysieren.\n" + "\n" + "Stunden wurden zu Tagen, und Tage wurden zu Wochen. Aber Herr Klein gab nicht auf. Schließlich, nach einem letzten tiefen Atemzug, schrieb er die letzte Zeile Code, die den magischen Code entsperrte. Mit einem leisen Klicken öffnete sich die Höhle, und eine leuchtende Kugel schwebte in die Luft. Aus ihr heraus hörte Herr Klein eine sanfte, weise Stimme:\n" + "\n" + "\"Du hast bewiesen, dass du das Herz eines wahren Programmierers trägst. Der magische Code gehört nun dir. Nutze ihn weise, um Gutes in die Welt zu bringen.\"\n" + "\n" + "Doch Herr Klein, so sehr er auch von der Macht des Codes beeindruckt war, wusste, dass die wahre Magie nicht darin lag, alle Antworten zu kennen. Es war die Freude am Lernen, am Lösen von Problemen und am Teilen seines Wissens mit anderen. Also kehrte er ins Dorf zurück und lehrte weiterhin seine Schüler. Aber jetzt brachte er ihnen nicht nur das Programmieren bei – er zeigte ihnen auch, wie man mit Geduld, Kreativität und einer Portion Mut selbst die kniffligsten Herausforderungen meistert.\n" + "\n" + "Und so lebte Herr Klein glücklich und zufrieden. Er fand Freude darin, seine Schüler zu inspirieren, und der magische Code ruhte sicher in seinem Herzen, bereit, nur dann genutzt zu werden, wenn es wirklich notwendig war. Und wenn die Dorfbewohner an seinen Fenstern vorbeigingen, konnten sie oft das leise Klicken seiner Tastatur hören, während Herr Klein weiter seine Leidenschaft verfolgte, eine Zeile Code nach der anderen.\n" + "\n" + "Und wenn er nicht gestorben ist, dann programmiert er noch heute.")); + System.out.println(lineSplitting("hgkjhgsdhjgsjhfgshjfghjsgfhjgshjkghgfjhsghjfgsjhkgfjksgfhjgdhgdfjhgsdhjgfdhjsgdfhjdfghjksgjhsdghjsdfgdshjgfjhsdgfjhs sdhjfgsdhfsdjhkshfdsghjdghjsghjdfgjhsgfsgfhjsgdhjfgsjfgjhsgdfshjgfshjdgfhjsdgjhsgfjhsgdjfgsjhgfdhjsgjhgdfjsdfg jfhgshjsdfgjsdgfgsfghd dsgsdfj")); + } + + public static Map tagStatistik(Path htmlDatei) { + Map statistik = new TreeMap<>(); + int counter = 0; + try { + for (String line : Files.readAllLines(htmlDatei)) { + Matcher matcher = Pattern.compile("(?<=<)\\w+").matcher(line); + while (matcher.find()) { + statistik.put(matcher.group(), statistik.getOrDefault(matcher.group(), 0.0) + 1); + counter++; + } + } + } catch (IOException e) { + System.err.println("Error while reading/ analysing File!"); + } + for (Map.Entry entry : statistik.entrySet()) + statistik.put(entry.getKey(), entry.getValue() / counter); + return statistik; + } + + public static Set links(Path htmlDatei) { + Set links = new HashSet<>(); + try { + for (String line : Files.readAllLines(htmlDatei)) { + Matcher matcher = Pattern.compile("(?<=href=\")https?://[^\"]+").matcher(line); + while (matcher.find()) links.add(matcher.group()); + } + } catch (IOException e) { + System.err.println("Error while reading/ analysing File!"); + } + return links; + } + + public static Set domains(Path htmlDatei) { + Set domains = new HashSet<>(); + try { + Pattern pattern = Pattern.compile("(?<=href=\"https?://)(?:\\w+\\.)*([\\w-]+\\.[a-zA-Z]{2,})"); + for (String line : Files.readAllLines(htmlDatei)) { + Matcher matcher = pattern.matcher(line); + while (matcher.find()) domains.add(matcher.group(1)); + } + } catch (IOException e) { + System.err.println("Error while reading/ analysing File!"); + } + return domains; + } + + public static Set klassen(Path cssDatei) { + Set classes = new HashSet<>(); + try { + Pattern pattern = Pattern.compile("(?<=\\.)[a-zA-Z]+[\\w-]*(?=.*\\{)"); + for (String line : Files.readAllLines(cssDatei)) { + Matcher matcher = pattern.matcher(line); + while (matcher.find()) classes.add(matcher.group()); + } + } catch (IOException e) { + System.err.println("Error while reading/ analysing File!"); + } + return classes; + } + + public static String removeMultipleSpaces(String string) { + return string.replaceAll(" +", " "); + } + + public static String bigStartingLetter(String string) { + return Pattern.compile("\\b[a-z]").matcher(string).replaceAll(matchResult -> matchResult.group().toUpperCase()); + } + + public static String lineSplitting(String string) { + if (Pattern.compile("\\b\\w{41,}\\b").matcher(string).find()) + throw new RuntimeException("A word with more than 40 letters was found!"); + Matcher matcher = Pattern.compile(".{1,40}(?:\\s|$)").matcher(string.replaceAll("\n", " ")); + StringBuilder output = new StringBuilder(); + while (matcher.find()) output.append(matcher.group().trim()).append("\n"); + return output.toString(); + } +} \ No newline at end of file diff --git a/src/UE06_151024_RegExp2/index.html b/src/UE06_151024_RegExp2/index.html new file mode 100644 index 0000000..9f5887e --- /dev/null +++ b/src/UE06_151024_RegExp2/index.html @@ -0,0 +1,1110 @@ + + + + + + + + + + HTL Rennweg – Die innovativste Schule Wiens + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +

HTL Rennweg

Alles, was deine Zukunft braucht.

+
+

HTL Rennweg

Alles, was deine Zukunft braucht.

+
+
+
+
+
+
+
+
+
TOFT - Tag der offenen Tür
+
+
+
+
+

Neues aus unserer Schule

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

ANMELDUNG FÜR DAS NÄCHSTE SCHULJAHR

Wie geht es nun weiter?

+
+
+
wir spenden für die Ukraine
+
+
+
+
+
+
+
+
+
+
+

UNSER AUSBILDUNGSANGEBOT

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + +
+
+ + © Copyright - HTL Rennweg - Impressum + + +
+ + +
+ + + +
+ +
+ + + +
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/UE06_151024_RegExp2/styles.css b/src/UE06_151024_RegExp2/styles.css new file mode 100644 index 0000000..a7b2d74 --- /dev/null +++ b/src/UE06_151024_RegExp2/styles.css @@ -0,0 +1,243 @@ +*{transition: all 0.2s;margin: 0px;} +html{ + scroll-behavior: smooth; + text-align: center; + font-family:'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif; +} +section{ + display: flex; + flex-direction: column; + row-gap: 30px; +} +a{ + text-decoration: none; + color: black; +} +p{ + font-size: 20px; +} +h1{ + font-size: 30px; + text-decoration: underline; +} +.mainNAV{ + background-color: rgba(53, 53, 53, 0.833); + padding: 15px; + padding-bottom: 20px; + position: fixed; + top: 0; + left: 0; + width: 100%; + box-sizing: border-box; + z-index: 5; +} +.mainNAV > div{ + display: flex; + max-width: 1000px; + margin: 0 auto; +} +.mainNAV > div{ + margin-top: 15px; +} +.mainNAV > div a{ + flex-grow: 1; + color: white; + margin: auto 15px; + font-size: 18px; + border: solid 2px rgb(128, 128, 128); + border-radius: 15px; + box-sizing: border-box; + background-image: url(../pictures/board.png); + background-color: rgba(48, 48, 48, 0.833); + background-size: 100%; + padding: 5px 0; +} +.mainNAV > div a:hover, .mainNAV img:hover{ + cursor: pointer; + transform: scale(1.2); +} +.wellcome{ + margin: 0 10px; + margin-top: 200px; + max-width: 800px; + align-self: center; +} +.toshop{ + align-self: center; +} +.toshop:hover{ + cursor: pointer; + transform: scale(1.2); +} +.toshop p{ + margin-top: 15px; + font-size: 30px; +} +.toshop a{ + display: flex; + flex-direction: column; + align-items: center; + padding: 25px 35px; + border-radius: 30px; + background-image: url(../pictures/board.png); + background-size: 100%; + text-decoration: none; + color: white; +} +.pizzabutton{ + width: 150px; + height: auto; + position: relative; + animation: rotate 4s linear infinite; +} +@keyframes rotate { + 0% { + transform: rotate(0deg); + } + 100% { + transform: rotate(360deg); + } +} +.menu{ + display: flex; + align-content: center; + flex-wrap: wrap; + align-items: center; + gap: 30px; + margin: 0 auto; + justify-content: center; + max-width: 1000px; +} +.menu li{ + text-align: left; +} +.menu img{ + width: 180px; +} +.menu > div{ + box-sizing: border-box; + background-image: url(../pictures/menu.jpg); + background-size: 100%; + border-radius: 30px; + padding: 25px; + width: 300px; + height: 446px; +} +.menu > div:hover{ + transform: scale(1.1); +} +.menu > div:hover > img{ + animation: menuRotate 4s linear infinite; +} +@keyframes menuRotate { + 0% { + transform: rotate(0deg); + } + 100% { + transform: rotate(360deg); + } +} +.menu *{ + color: white; + font-size: 25px; +} +.menu sup{ + font-size: 20px; +} +.menu p{ + margin: 15px 0; + font-weight: bold; + text-decoration: underline; +} +.aboutUS{ + max-width: 800px; + margin: 0 auto; +} +.location { + background-color: #f8f8f8; + padding: 40px 0; + text-align: center; +} + +.location h1 { + font-size: 28px; + margin-bottom: 20px; + color: #333; +} + +.contact { + background-color: #fff; + padding: 40px 0; + text-align: center; +} + +.contact h1 { + font-size: 28px; + margin-bottom: 20px; + color: #333; +} + +.contact p { + font-size: 20px; + margin: 10px 0; + color: #555; +} + + +.allergene{ + text-align: center; +} +.allergene h1{ + font-size: 30px; + color: black; +} +table { + width: 60%; + margin: 20px auto; + border-collapse: collapse; +} +th, td { + padding: 10px; + text-align: center; + border: 1px solid darkgray; +} +th { + background-color: darkgray; + color: white; +} +tr:hover { + background-color: lightgray; +} +footer{ + background-color: black; + color: white; + padding: 20px; +} +/*Small*/ +@media (max-width: 600px) { + .mainNAV > div{ + display: grid; + grid-template-columns: 1fr 1fr; + grid-auto-rows: 31px; + row-gap: 15px; + } + .WE{ + grid-column: 1; + grid-row: 1; + } + .MU{ + grid-column: 2; + grid-row: 1; + } + .AUS{ + grid-column: 1; + grid-row: 2; + } + .LOC{ + grid-column: 2; + grid-row: 2; + } +} +#wellcome, #menu, #aboutUS, #location { + scroll-margin-top: 170px; +} \ No newline at end of file diff --git a/src/UE07_221024_RegExp3/SEW3_UE06_2024_RegEx3_Chem.pdf b/src/UE07_221024_RegExp3/SEW3_UE06_2024_RegEx3_Chem.pdf new file mode 100644 index 0000000..cd21706 Binary files /dev/null and b/src/UE07_221024_RegExp3/SEW3_UE06_2024_RegEx3_Chem.pdf differ diff --git a/src/UE08_051124_Rekursion/SEW3 UE08 2024_Rekursion1,Sierpinski.pdf b/src/UE08_051124_Rekursion/SEW3 UE08 2024_Rekursion1,Sierpinski.pdf new file mode 100644 index 0000000..3f6ba2e Binary files /dev/null and b/src/UE08_051124_Rekursion/SEW3 UE08 2024_Rekursion1,Sierpinski.pdf differ diff --git a/src/UE08_051124_Rekursion/Sierpinski_Dreieck.java b/src/UE08_051124_Rekursion/Sierpinski_Dreieck.java new file mode 100644 index 0000000..8707344 --- /dev/null +++ b/src/UE08_051124_Rekursion/Sierpinski_Dreieck.java @@ -0,0 +1,42 @@ +package UE08_051124_Rekursion; + + +import javafx.application.Application; +import javafx.geometry.Point2D; +import javafx.scene.Scene; +import javafx.scene.canvas.Canvas; +import javafx.scene.canvas.GraphicsContext; +import javafx.scene.layout.BorderPane; +import javafx.stage.Stage; + +public class Sierpinski_Dreieck extends Application { + + static final int canvasWidth = 580; + static final int canvasHeight = 502; + static final int minSize = 10; + + public static void main(String[] args) { + Application.launch(args); + } + + @Override + public void start(Stage primaryStage) { + primaryStage.setTitle("Sierpinski-Dreieck"); + Canvas canvas = new Canvas(canvasWidth, canvasHeight); + primaryStage.setResizable(false); + primaryStage.setScene(new Scene(new BorderPane(canvas))); + primaryStage.show(); + Point2D p1 = new Point2D(0, canvas.getHeight()), p2 = new Point2D(canvas.getWidth(), canvas.getHeight()), p3 = new Point2D(canvas.getWidth() / 2, 0); + drawSierpinskiTriangle(canvas.getGraphicsContext2D(), minSize, p1, p2, p3); + } + + private void drawSierpinskiTriangle(GraphicsContext gc, int size, Point2D p1, Point2D p2, Point2D p3) { + if (p2.getX() - p1.getX() <= size) return; + gc.strokeLine(p1.getX(), p1.getY(), p2.getX(), p2.getY()); + gc.strokeLine(p2.getX(), p2.getY(), p3.getX(), p3.getY()); + gc.strokeLine(p1.getX(), p1.getY(), p3.getX(), p3.getY()); + drawSierpinskiTriangle(gc, size, p1, p1.midpoint(p2), p1.midpoint(p3)); + drawSierpinskiTriangle(gc, size, p1.midpoint(p2), p2, p2.midpoint(p3)); + drawSierpinskiTriangle(gc, size, p1.midpoint(p3), p2.midpoint(p3), p3); + } +} \ No newline at end of file diff --git a/src/UE08_051124_Rekursion/UE08_Rekursion.java b/src/UE08_051124_Rekursion/UE08_Rekursion.java new file mode 100644 index 0000000..4137f7f --- /dev/null +++ b/src/UE08_051124_Rekursion/UE08_Rekursion.java @@ -0,0 +1,39 @@ +package UE08_051124_Rekursion; + +public class UE08_Rekursion { + public static void main(String[] args) { + printFibonacciFolge(8); + System.out.println(zaehleSelbstlaute("Hallo du MENSCH")); + System.out.println(zahlHoch(2, 5)); + System.out.println(zahlHoch(2, 10)); + System.out.println(zahlHoch(1, 1)); + System.out.println(zahlHoch(1, 10)); + System.out.println(zahlHoch(5, 5)); + System.out.println(zahlHoch(20, 3)); + System.out.println(zahlHoch(10, 1)); + System.out.println(zahlHoch(10, 10)); + } + + public static int fibonacci(int n) { + return n <= 2 ? n <= 0 ? 0 : 1 : fibonacci(n - 1) + fibonacci(n - 2); + } + + public static void printFibonacciFolge(int anz) { + for (int i = 1; i <= anz; i++) System.out.print(fibonacci(i) + " "); + } + + public static int zaehleSelbstlaute(String s) { +// if (s.isEmpty()) return 0; +// if ("aeiouAEIOU".indexOf(s.charAt(0)) == -1) return 0; +// return 1 + zaehleSelbstlaute(s.substring(1)); + return s.isEmpty() ? 0 : (("aeiouAEIOU".indexOf(s.charAt(0)) == -1) ? 0 : 1) + zaehleSelbstlaute(s.substring(1)); + } + + public static long zahlHoch(int x, int n) { +// if (n <= 1) return x; +// long z = zahlHoch(x, n >> 1); +// if ((n & 1) != 0) return x * z * z; +// return z * z; + return n <= 1 ? x : ((n & 1) != 0 ? x * zahlHoch(x, n >> 1) * zahlHoch(x, n >> 1) : zahlHoch(x, n >> 1) * zahlHoch(x, n >> 1)); + } +}