From e0281db2c08647cc36b8a7ef3122d646970b1c0d Mon Sep 17 00:00:00 2001 From: eronahasani Date: Thu, 11 Dec 2025 23:26:20 +0100 Subject: [PATCH] =?UTF-8?q?+=20shopTUI=20Klasse=20erweitert=20=09+=20Haupt?= =?UTF-8?q?men=C3=BC=20=09=09+=20Suchoption=20=09=09+=20Warenkorbeinsicht?= =?UTF-8?q?=20=09=09+=20Beenden=20=09+=20in=20suche=20Methode=20=09=09+=20?= =?UTF-8?q?zum=20Warenkorb=20mit=20gew=C3=BCnschter=20Menge=20hinzuf=C3=BC?= =?UTF-8?q?gen=20=09+=20in=20angebot=20Methode=20=09=09+=20zum=20Warenkorb?= =?UTF-8?q?=20mit=20gew=C3=BCnschter=20Menge=20hinzuf=C3=BCgen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OS-Abgabe/src/backend/Warenkorb.java | 27 +++-- OS-Abgabe/src/tui/shopTUI.java | 145 ++++++++++++++++++++------- 2 files changed, 129 insertions(+), 43 deletions(-) diff --git a/OS-Abgabe/src/backend/Warenkorb.java b/OS-Abgabe/src/backend/Warenkorb.java index aec4d40..b3861cd 100644 --- a/OS-Abgabe/src/backend/Warenkorb.java +++ b/OS-Abgabe/src/backend/Warenkorb.java @@ -8,8 +8,10 @@ public class Warenkorb { inhalt = new ArrayList(); } - public void produktHinzufügen(Produkt p) { - inhalt.add(p); + public void produktHinzufügen(Produkt p, int menge) { + for (int i = 0; i < menge; i++) { + inhalt.add(p); + } } public double berechneGesamtpreis() { @@ -20,9 +22,22 @@ public class Warenkorb { } public void anzeigen() { - System.out.println("(。•◡•。) Hier ist Ihr aktueller Warenkorb: "); - for (Produkt p : inhalt) - System.out.println(p); - System.out.println("Betrag: " + berechneGesamtpreis() + "€ ૮˶ᵔᵕᵔ˶ა"); + if (inhalt.size() == 0) { + System.out.println(); + System.out.println(); + System.out.println("Ihr Warenkorb ist leer (˶ᵕ˶)⸝♡"); + System.out.println("Ab zum Hauptmenü... ٩(^ᗜ^ )و"); + System.out.println(); + System.out.println(); + System.out.println(); + } else { + System.out.println(); + System.out.println(); + System.out.println("(。•◡•。) Hier ist Ihr aktueller Warenkorb: "); + for (Produkt p : inhalt) { + System.out.println(p); + System.out.println("Ihre Summe beträgt " + berechneGesamtpreis() + "€ ૮˶ᵔᵕᵔ˶ა"); + } + } } } diff --git a/OS-Abgabe/src/tui/shopTUI.java b/OS-Abgabe/src/tui/shopTUI.java index d59c1a0..d20e826 100644 --- a/OS-Abgabe/src/tui/shopTUI.java +++ b/OS-Abgabe/src/tui/shopTUI.java @@ -1,6 +1,7 @@ package tui; import backend.OnlineShop; import backend.Produkt; +import backend.Warenkorb; import java.util.Scanner; import java.io.FileNotFoundException; @@ -8,62 +9,132 @@ import java.io.FileNotFoundException; public class shopTUI { private static OnlineShop shop; + public static Warenkorb warenkorb = new Warenkorb(); private static Scanner sc = new Scanner(System.in); public static void main(String[] args) throws FileNotFoundException { System.out.println("Willkommen bei Onami! („•֊•„)੭"); shop = new OnlineShop(); - - angebot(); - - suche(); - - System.out.println("Auf Wiedersehen! (づ˶•༝•˶)づ "); + hauptmenü(); } public static void hauptmenü() { - // TODO: hier ein erstes Menü mit bspw. - // Produktangebot - // Produktsuche - // Warenkorbanzeige - // evtl. Bestellung (kann auch über Warenkorb realisiert werden) - // Exit + System.out.println(); + System.out.println(" ⋆ ˚。⋆ Hauptmenü ⋆ ˚。⋆ "); + System.out.println(" ⏔⏔⏔⏔⏔⏔⏔ ꒰ ᧔ෆ᧓ ꒱ ⏔⏔⏔⏔⏔⏔⏔ "); + System.out.println(" Produktangebot "); + System.out.println(" Produktsuche "); + System.out.println(" Warenkorb "); + System.out.println(" Beenden "); + System.out.println(" ⏔⏔⏔⏔⏔⏔⏔⏔⏔⏔⏔⏔⏔⏔⏔⏔⏔⏔⏔"); + System.out.println(); + System.out.print("Bitte geben Sie eine der Optionen an: "); + + String eingabe = sc.nextLine().toLowerCase(); + + if (eingabe.equals("produktangebot")) { + angebot(); + } else if (eingabe.equals("produktsuche")) { + suche(); + } else if (eingabe.equals("warenkorb")) { + warenkorb.anzeigen(); + } else if (eingabe.equals("beenden")) { + System.out.println("\n\n\n | ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄| "); + System.out.println(" Auf Wiedersehen! "); + System.out.println(" |______________| "); + System.out.println(" \\ (• ᴗ •) / "); + System.out.println(" \\ / "); + } else { + System.out.println("\n\n Bitte prüfen Sie Ihre Eingabe und versuchen Sie es erneut: "); + hauptmenü(); + } } + public static void angebot() { - System.out.println("૮ ྀིᴗ͈.ᴗ͈ ྀིა Was wir Ihnen anbieten:"); - System.out.println(); - + System.out.println("\n\n\n૮ ྀིᴗ͈.ᴗ͈ ྀིა Unser Angebot: \n"); String[] produkte = shop.produktListe(); - for (int i = 0; i < produkte.length; i++) - System.out.println(produkte[i]); + for (int i = 0; i < produkte.length; i++) { + Produkt p = shop.lager.get(i); + System.out.printf("%-3d | %-25s | %.2f€\n", p.id, p.name, p.preis); + } + + System.out.println(); + System.out.println("Wählen Sie ein Produkt anhand der Artikelnummer für Ihren Warenkorb aus \noder geben Sie 'Hauptmenü' an, wenn Sie zurück wollen: "); + String eingabe = sc.nextLine().toLowerCase(); + + if (eingabe.equals("hauptmenü")) { + hauptmenü(); + return; + } + + int nummer = Integer.parseInt(eingabe); + int index = nummer - 1; + + Produkt p = shop.lager.get(index); + System.out.println("\n\n\nSie haben folgendes ausgewählt: " + p.name); + System.out.println("(„•֊•„) Geben Sie bitte die gewünschte Menge an: \n"); + int menge = Integer.parseInt(sc.nextLine()); + if (menge <= p.bestand) { + warenkorb.produktHinzufügen(p, menge); + p.bestand -= menge; + System.out.println("Das Produkt wurde in der gewünschten Menge zum Warenkorb hinzugefügt ✧。٩(ˊᗜˋ)و✧*。"); + } else { + System.out.println("Leider reicht unser Bestand nicht aus (˃̣̣̥ᯅ˂̣̣̥)"); + } + System.out.println("Ab zum Hauptmenü... ٩(^ᗜ^ )و \n\n\n"); + hauptmenü(); } public static void suche() { - System.out.println(); - System.out.println("(˶˃ᵕ˂˶) Was suchen Sie? "); + System.out.println("\n(˶˃ᵕ˂˶) Wonach suchen Sie?: "); String suchbegriff = sc.nextLine().toLowerCase(); - if (suchbegriff.length() == 0) return; + + if (suchbegriff.length() == 0) return; + if (suchbegriff.equals("hauptmenü")) return; boolean gefunden = false; - - for (int artnr = 0; artnr < shop.lager.size(); artnr++) { - Produkt p = shop.lager.get(artnr); - - for (int i = 0; i <= p.name.length() - suchbegriff.length(); i++) { - if (p.name.substring(i, i + suchbegriff.length()).toLowerCase().equals(suchbegriff)) { - if(!gefunden) { - System.out.println(); - System.out.println(); - System.out.println("(˶ˆᗜˆ˵) Wir haben folgenden Treffer: "); - } - System.out.println(p); - gefunden = true; - break; - } + + for (int artnr = 0; artnr < shop.lager.size(); artnr++) { + Produkt p = shop.lager.get(artnr); + + for (int i = 0; i <= p.name.length() - suchbegriff.length(); i++) { + if (p.name.substring(i, i + suchbegriff.length()).toLowerCase().equals(suchbegriff)) { + if(!gefunden) { + System.out.println("\n(˶ˆᗜˆ˵) Wir haben folgenden Treffer zu bieten: "); + } + System.out.println(p); + gefunden = true; + + System.out.println("\nMöchten Sie das Produkt zu Ihrem Warenkorb hinzufügen? (✿◠ᴗ◠)"); + String antwort = sc.nextLine().toLowerCase(); + if (antwort.equals("ja")) { + System.out.println("(„•֊•„) Geben Sie bitte die gewünschte Menge an: "); + int menge = Integer.parseInt(sc.nextLine()); + + if (menge <= p.bestand) { + warenkorb.produktHinzufügen(p, menge); + p.bestand -= menge; + System.out.println("Das Produkt wurde in der gewünschten Menge zum Warenkorb hinzugefügt ✧。٩(ˊᗜˋ)و✧*。"); + System.out.println("Ab zum Hauptmenü... ٩(^ᗜ^ )و \n\n\n"); + hauptmenü(); + } else { + System.out.println("Leider reicht unser Bestand nicht aus (˃̣̣̥ᯅ˂̣̣̥)"); + System.out.println("Ab zum Hauptmenü... ٩(^ᗜ^ )و \n\n\n"); + hauptmenü(); + } + } else { + System.out.println("Ab zum Hauptmenü... ٩(^ᗜ^ )و \n\n\n"); + hauptmenü(); + } + } + } } + if (!gefunden) { + System.out.println("Leider keine Treffer (˃̣̣̥ᯅ˂̣̣̥)"); + System.out.println("Ab zum Hauptmenü... ٩(^ᗜ^ )و \n\n\n"); + hauptmenü(); + } } - if (!gefunden) System.out.println("Leider keine Treffer (˃̣̣̥ᯅ˂̣̣̥)"); - } }