+ 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>(); inhalt = new ArrayList<Produkt>();
} }
public void produktHinzufügen(Produkt p) { public void produktHinzufügen(Produkt p, int menge) {
inhalt.add(p); for (int i = 0; i < menge; i++) {
inhalt.add(p);
}
} }
public double berechneGesamtpreis() { public double berechneGesamtpreis() {
@ -20,9 +22,22 @@ public class Warenkorb {
} }
public void anzeigen() { public void anzeigen() {
System.out.println("(。•◡•。) Hier ist Ihr aktueller Warenkorb: "); if (inhalt.size() == 0) {
for (Produkt p : inhalt) System.out.println();
System.out.println(p); System.out.println();
System.out.println("Betrag: " + berechneGesamtpreis() + "€ ૮˶ᵔᵕᵔ˶ა"); 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; package tui;
import backend.OnlineShop; import backend.OnlineShop;
import backend.Produkt; import backend.Produkt;
import backend.Warenkorb;
import java.util.Scanner; import java.util.Scanner;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -8,62 +9,132 @@ import java.io.FileNotFoundException;
public class shopTUI { public class shopTUI {
private static OnlineShop shop; private static OnlineShop shop;
public static Warenkorb warenkorb = new Warenkorb();
private static Scanner sc = new Scanner(System.in); private static Scanner sc = new Scanner(System.in);
public static void main(String[] args) throws FileNotFoundException { public static void main(String[] args) throws FileNotFoundException {
System.out.println("Willkommen bei Onami! („•֊•„)੭"); System.out.println("Willkommen bei Onami! („•֊•„)੭");
shop = new OnlineShop(); shop = new OnlineShop();
hauptmenü();
angebot();
suche();
System.out.println("Auf Wiedersehen! (づ˶•༝•˶)づ ");
} }
public static void hauptmenü() { public static void hauptmenü() {
// TODO: hier ein erstes Menü mit bspw. System.out.println();
// Produktangebot System.out.println(" ⋆ ˚。⋆ Hauptmenü ⋆ ˚。⋆ ");
// Produktsuche System.out.println(" ⏔⏔⏔⏔⏔⏔⏔ ꒰ ᧔ෆ᧓ ꒱ ⏔⏔⏔⏔⏔⏔⏔ ");
// Warenkorbanzeige System.out.println(" Produktangebot ");
// evtl. Bestellung (kann auch über Warenkorb realisiert werden) System.out.println(" Produktsuche ");
// Exit 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() { public static void angebot() {
System.out.println("૮ ྀིᴗ͈.ᴗ͈ ྀིა Was wir Ihnen anbieten:"); System.out.println("\n\n\n૮ ྀིᴗ͈.ᴗ͈ ྀིა Unser Angebot: \n");
System.out.println();
String[] produkte = shop.produktListe(); String[] produkte = shop.produktListe();
for (int i = 0; i < produkte.length; i++) for (int i = 0; i < produkte.length; i++) {
System.out.println(produkte[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() { public static void suche() {
System.out.println(); System.out.println("\n(˶˃ᵕ˂˶) Wonach suchen Sie?: ");
System.out.println("(˶˃ᵕ˂˶) Was suchen Sie? ");
String suchbegriff = sc.nextLine().toLowerCase(); String suchbegriff = sc.nextLine().toLowerCase();
if (suchbegriff.length() == 0) return;
if (suchbegriff.length() == 0) return;
if (suchbegriff.equals("hauptmenü")) return;
boolean gefunden = false; boolean gefunden = false;
for (int artnr = 0; artnr < shop.lager.size(); artnr++) { for (int artnr = 0; artnr < shop.lager.size(); artnr++) {
Produkt p = shop.lager.get(artnr); Produkt p = shop.lager.get(artnr);
for (int i = 0; i <= p.name.length() - suchbegriff.length(); i++) { for (int i = 0; i <= p.name.length() - suchbegriff.length(); i++) {
if (p.name.substring(i, i + suchbegriff.length()).toLowerCase().equals(suchbegriff)) { if (p.name.substring(i, i + suchbegriff.length()).toLowerCase().equals(suchbegriff)) {
if(!gefunden) { if(!gefunden) {
System.out.println(); System.out.println("\n(˶ˆᗜˆ˵) Wir haben folgenden Treffer zu bieten: ");
System.out.println(); }
System.out.println("(˶ˆᗜˆ˵) Wir haben folgenden Treffer: "); System.out.println(p);
} gefunden = true;
System.out.println(p);
gefunden = true; System.out.println("\nMöchten Sie das Produkt zu Ihrem Warenkorb hinzufügen? (✿◠ᴗ◠)");
break; 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 (˃̣̣̥ᯅ˂̣̣̥)");
}
} }