OnlineShop/src/ShopTUI.java

101 lines
3.8 KiB
Java

import java.io.FileNotFoundException;
import java.util.Scanner;
public class ShopTUI {
public static OnlineShop shop;
public static void main(String[] args) throws FileNotFoundException {
System.out.println("Willkommen im Lewandowski Store!\n \n");
shop = new OnlineShop();
produktangebot();
hauptmenu();
}
public static void hauptmenu() throws FileNotFoundException {
System.out.println("Was möchten Sie tun? \n(1=Produktsuche, 2=Warenkorbanzeige, 3=Bestellung abschließen, 0=Programm beenden): ");
while (true) {
Scanner scanner = new Scanner(System.in);
int wahl = scanner.nextInt();
switch (wahl) {
case 1:
produktsuche();
break;
case 2:
shop.warenkorbAusgabe();
System.out.println("\n \n Möchten Sie gerne Änderungen vornehmen? \n 1=Produkte löschen, 2=Menge verändern, 3=Zurück zum Hauptmenü");
int warenkorbAuswahl = scanner.nextInt();
if (warenkorbAuswahl == 1 || warenkorbAuswahl == 2) {
shop.warenkorbÄnderungen(warenkorbAuswahl);
hauptmenu();
}
else if (warenkorbAuswahl == 3) {
hauptmenu();
}
break;
case 3:
break;
case 0:
System.exit(0);
break;
default: System.out.println("Falsche Eingabe!");
continue;
}
}
}
public static void produktangebot() throws FileNotFoundException {
System.out.println("Diese Produkte bieten wir an: \n");
shop.produkteListe();
}
public static void produktsuche() throws FileNotFoundException {
while (true) {
System.out.println("Geben Sie das gewünschte Produkt mit der ProduktNr an");
System.out.println("(0 für Anzeige der Produktinformationen, " + (shop.lager.size() + 1) + " um zum Hauptmenü zurückzukehren)");
Scanner scanner = new Scanner(System.in);
int produktNr = scanner.nextInt();
if (produktNr == 0) {
shop.produkteInformationen();
continue;
} else if (produktNr == shop.lager.size() + 1) {
break;
}
int eingabe = 0;
System.out.println("Wie viele möchten Sie in Warenkorb legen?");
scanner = new Scanner(System.in);
int menge = scanner.nextInt();
System.out.println("(" + shop.lager.get(produktNr - 1) + ") " + menge + " mal in den Warenkorb legen? (1=Ja, 2=Nein)");
scanner = new Scanner(System.in);
while (true) {
eingabe = scanner.nextInt();
if (eingabe == 1) {
shop.inWarenkorb(produktNr, menge);
System.out.println("Möchten Sie ein weiteres Produkt hinzufügen? (1=Ja, 2=Nein)");
scanner = new Scanner(System.in);
eingabe = scanner.nextInt();
if (eingabe == 1) {
produktsuche();
}
else if (eingabe == 2) {
hauptmenu();
}
else{ System.out.println("Probieren Sie es erneut");}
} else if (eingabe == 2) {
produktsuche();
}
System.out.println("Probieren Sie es erneut.");
continue;
}
}
}
}