+ shopTUI Klasse erweitert

+ Hauptmenü
		+ Suchoption
		+ Warenkorbeinsicht
		+ Beenden
	+ in suche Methode
		+ zum Warenkorb mit gewünschter Menge hinzufügen
	+ in angebot Methode
		+ zum Warenkorb mit gewünschter Menge hinzufügen
main
eronahasani 2025-12-11 23:26:20 +01:00
parent fba7b85542
commit e0281db2c0
2 changed files with 129 additions and 43 deletions

View File

@ -8,8 +8,10 @@ public class Warenkorb {
inhalt = new ArrayList<Produkt>();
}
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() + "€ ૮˶ᵔᵕᵔ˶ა");
}
}
}
}

View File

@ -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 (˃̣̣̥ᯅ˂̣̣̥)");
}
}