OS-Abgabe/OS-Abgabe/src/tui/shopTUI.java

262 lines
11 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package tui;
import backend.WarenkorbPosition;
import backend.OnlineShop;
import backend.Produkt;
import backend.Warenkorb;
import backend.Bestellung;
import java.util.Scanner;
import java.io.FileNotFoundException;
public class shopTUI {
private static OnlineShop shop;
private 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();
warenkorb = new Warenkorb();
hauptmenü();
}
public static void hauptmenü() {
System.out.println("\n ⋆ ˚。⋆ Hauptmenü ⋆ ˚。⋆ ");
System.out.println(" ⏔⏔⏔⏔⏔⏔⏔ ꒰ ᧔ෆ᧓ ꒱ ⏔⏔⏔⏔⏔⏔⏔ ");
System.out.println(" Produktangebot ");
System.out.println(" Produktsuche ");
System.out.println(" Warenkorb ");
System.out.println(" Beenden ");
System.out.println(" ⏔⏔⏔⏔⏔⏔⏔⏔⏔⏔⏔⏔⏔⏔⏔⏔⏔⏔⏔ \n");
System.out.print("Bitte geben Sie eine der Optionen an: ");
String eingabe = sc.nextLine().toLowerCase();
if (eingabe.equals("produktangebot") || eingabe.equals("angebot")) {
angebot();
} else if (eingabe.equals("produktsuche") || eingabe.equals("suche")) {
suche();
} else if (eingabe.equals("warenkorb")) {
warenkorb();
} 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 Ungültige Eingabe (˃̣̣̥ᯅ˂̣̣̥) Versuchen Sie es bitte erneut:");
hauptmenü();
}
}
public static void angebot() {
System.out.println("\n\n\n૮ ྀིᴗ͈.ᴗ͈ ྀིა Unser Angebot: \n");
String[] produkte = shop.produktListe();
for (int i = 0; i < produkte.length; i++) {
Produkt p = shop.lager.get(i);
System.out.printf(" %-2d | %-23s | %.2f€\n", p.getId(), p.getName(), p.getPreis());
}
System.out.println("\nWä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ü();
}
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.getName());
System.out.println("(„•֊•„) Geben Sie bitte die gewünschte Menge an: \n");
int menge = Integer.parseInt(sc.nextLine());
if (menge <= p.getBestand()) {
warenkorb.produktHinzufügen(p, menge);
shop.reduzieren(p, 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("\n(˶˃ᵕ˂˶) Wonach suchen Sie?: ");
String suchbegriff = sc.nextLine().toLowerCase();
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.getName().length() - suchbegriff.length(); i++) {
if (p.getName().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.getBestand()) {
warenkorb.produktHinzufügen(p, menge);
shop.reduzieren(p, 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ü();
}
}
public static void warenkorb() {
if (warenkorb.getPositionen().size() == 0) {
System.out.println("\n\nIhr Warenkorb ist leer (˶ᵕ˶)⸝♡");
System.out.println("Ab zum Hauptmenü... ٩(^ᗜ^ )و \n\n\n");
hauptmenü();
} else {
System.out.println("\n⟡ . ݁₊ ⊹ . ݁˖ . ݁ . ݁₊ Warenkorbübersicht . ݁ ˖ . ݁ . ݁₊ ⊹ . ݁˖ ݁.⟡");
System.out.println("⟡ . ݁ ݁.⟡");
int pos = 1;
for (WarenkorbPosition wp : warenkorb.getPositionen()) {
System.out.printf("⟡ . ݁ Pos.: %2d | %2dx | %-23s | %6.2f€ ݁.⟡\n",
pos++,
wp.getMenge(),
wp.getProdukt().getName(),
wp.getProdukt().getPreis());
}
System.out.println("⟡ . ݁ ݁.⟡");
double gesamtpreis
= warenkorb.produkteNetto()
+ warenkorb.produkteMwst()
+ warenkorb.versandNetto()
+ warenkorb.versandMwst();
System.out.printf("⟡ . ݁ %-29s %19.2f€ ݁.⟡\n", "Nettosumme:", warenkorb.produkteNetto());
System.out.printf("⟡ . ݁ %-29s %19.2f€ ݁.⟡\n", "MwSt:", warenkorb.produkteMwst());
System.out.println("⟡ . ݁ ݁.⟡");
System.out.printf("⟡ . ݁ %-29s %19.2f€ ݁.⟡\n", "Versandkosten:", warenkorb.versandNetto());
System.out.printf("⟡ . ݁ %-29s %19.2f€ ݁.⟡\n", "MwSt Versand:", warenkorb.versandMwst());
System.out.println("⟡ . ݁ ݁.⟡");
System.out.printf("⟡ . ݁ %-29s %19.2f€ ݁.⟡\n", "Gesamt Brutto:", gesamtpreis);
System.out.println("⟡ . ݁ ݁.⟡");
System.out.println("⟡ . ݁₊ ⊹ . ݁˖ . ݁ . ݁ ₊ ⊹ . ݁˖ . ݁ ⟡ . ݁₊ ⊹ . ݁˖ . ݁ . ݁₊ ⊹ . ݁˖ ݁.⟡");
System.out.println("\n\n\nMöchten Sie bestellen, die Menge ändern oder zurück zum Hauptmenü?: ");
String eingabe = sc.nextLine().toLowerCase();
if (eingabe.equals("hauptmenü") || eingabe.equals("menü")) {
hauptmenü();
} else if (eingabe.equals("menge ändern") || eingabe.equals("die menge ändern") || eingabe.equals("ändern")) {
menge();
} else if (eingabe.equals("bestellen")) {
bestellen();
} else {
System.out.println("\n\n Ungültige Eingabe (˃̣̣̥ᯅ˂̣̣̥) Versuchen Sie es bitte erneut: \n\n");
warenkorb();
}
}
}
public static void bestellen() {
System.out.print("Bitte geben Sie Ihren vollständigen Namen ein: ");
String name = sc.nextLine();
System.out.print("\nBitte geben Sie Ihre Lieferadresse ein: ");
String adresse = sc.nextLine();
Bestellung bestellung = new Bestellung(name, adresse, warenkorb);
System.out.println("\n\n\n\n\n(\\ (\\");
System.out.println("(„• ֊ •„) Danke schön für Ihre Bestellung!");
System.out.println("━O━O━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
System.out.println("Name: \n" + bestellung.getName());
System.out.println("\nAdresse: \n" + bestellung.getAdresse());
System.out.println("\nArtikel:" );
int artpos = 1;
for (WarenkorbPosition wp : bestellung.getWarenkorb().getPositionen()) {
System.out.printf("Pos.: %2d. | %2d | %-23s | %.2f€\n",
artpos++,
wp.getMenge(),
wp.getProdukt().getName(),
wp.getProdukt().getPreis());
}
System.out.printf("\nGesamtpreis: \n%.2f€\n", bestellung.getGesamtpreis());
System.out.println("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
warenkorb = new Warenkorb();
System.out.println("\n\nIhr Warenkorb wurde geleert! ◝(˶˃ᵕ˂˶)◜");
System.out.println("Ab zum Hauptmenü... ٩(^ᗜ^ )و \n\n\n");
hauptmenü();
}
public static void menge() {
System.out.print("Welche Position möchten Sie bearbeiten?: ");
int posNr = Integer.parseInt(sc.nextLine()) - 1;
if (posNr < 0 || posNr >= warenkorb.getPositionen().size()) {
System.out.println("Ungültige Eingabe (˃̣̣̥ᯅ˂̣̣̥) Versuchen Sie es bitte erneut:");
warenkorb();
return;
}
WarenkorbPosition wp = warenkorb.getPositionen().get(posNr);
Produkt p = wp.getProdukt();
int alt = wp.getMenge();
System.out.print("\nGeben Sie bitte die neue Menge an: ");
int neu = Integer.parseInt(sc.nextLine());
int x = neu - alt;
if (neu == 0) {
shop.erhöhen(p, alt);
warenkorb.entfernen(p);
System.out.println("Die Position wurde gelöscht! ✧。٩(ˊᗜˋ)و✧*。");
} else if (x > 0 && p.getBestand() < x) {
System.out.println("Leider reicht unser Bestand nicht aus (˃̣̣̥ᯅ˂̣̣̥)");
} else {
if (x > 0) shop.reduzieren(p, x);
else if (x < 0) shop.erhöhen(p, -x);
warenkorb.mengeAendern(p, neu);
System.out.println("Die Menge wurde geändert! ✧。٩(ˊᗜˋ)و✧*。");
}
warenkorb();
}
}