176 lines
5.5 KiB
Java
176 lines
5.5 KiB
Java
package tui;
|
|
import backend.OnlineShop;
|
|
|
|
import java.io.File;
|
|
import java.io.FileNotFoundException;
|
|
import java.util.ArrayList;
|
|
import java.util.Scanner;
|
|
|
|
public class ShopTUI {
|
|
private static OnlineShop shop;
|
|
private static Scanner sc;
|
|
public static void main(String[] args) throws FileNotFoundException {
|
|
shop = new OnlineShop();
|
|
sc = new Scanner(System.in);
|
|
shop.AddProdukteVonDatei(readFile("resources/produkte.csv"));
|
|
Menu();
|
|
System.out.println("Ende.");
|
|
}
|
|
|
|
private static void Menu() {
|
|
Boolean ende = false;
|
|
while(!ende) {
|
|
if(!shop.validWarenkorb()) {
|
|
UpdateKundeInWarenkorb();
|
|
continue;
|
|
}
|
|
System.out.println();
|
|
System.out.println("Wählen Sie:");
|
|
System.out.println("1) Alle Produkte anzeigen");
|
|
System.out.println("2) Produkt nach Namen suchen");
|
|
System.out.println("3) Produkt anhand der id hinzufügen/ löschen");
|
|
System.out.println("4) Warenkorb anzeigen");
|
|
System.out.println("5) Warenkorb leeren");
|
|
System.out.println("6) Kundendaten ändern");
|
|
System.out.println("7) Bestellen");
|
|
//System.out.println("8) Alte Bestellungen anzeigen");
|
|
System.out.println("9) exit");
|
|
System.out.println();
|
|
String orgeingabe = sc.nextLine();
|
|
if(!(orgeingabe.length()>0&&(orgeingabe.charAt(0)>'0'&&orgeingabe.charAt(0)<='9'))) {
|
|
continue;
|
|
}
|
|
int eingabe = Integer.parseInt(""+orgeingabe.charAt(0));
|
|
switch (eingabe) {
|
|
case 1 :
|
|
ShowProdukte();
|
|
break;
|
|
case 2 :
|
|
SearchProdukt();
|
|
break;
|
|
case 3 :
|
|
AddProdukt();
|
|
break;
|
|
case 4 :
|
|
ShowWarenkorb();
|
|
break;
|
|
case 5 :
|
|
ResetWarenkorb();
|
|
break;
|
|
case 6 :
|
|
UpdateKundeInWarenkorb();
|
|
break;
|
|
case 7 :
|
|
Bestellen();
|
|
break;
|
|
case 8 :
|
|
ShowBestellungen();
|
|
break;
|
|
case 9 :
|
|
ende = true;
|
|
break;
|
|
default :
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
private static void ShowProdukte(){
|
|
ArrayList<String[]> produkte = shop.ShowProdukte();
|
|
for(int i = 0; i < produkte.size(); i++) {
|
|
System.out.println("id: "+produkte.get(i)[0]);
|
|
System.out.println("Name: "+produkte.get(i)[1]);
|
|
System.out.println("Gewicht: "+produkte.get(i)[2]+"g");
|
|
System.out.println("Nettopreis: "+produkte.get(i)[3]+"ct");
|
|
System.out.println("MwStSatz: "+produkte.get(i)[4]+"%");
|
|
System.out.println("Lagerbestand: "+produkte.get(i)[5]);
|
|
System.out.println("");
|
|
}
|
|
};
|
|
private static void SearchProdukt(){
|
|
System.out.println("Bitte schreiben Sie den Suchbegriff:");
|
|
String orgeingabe = sc.nextLine();
|
|
ArrayList<String[]> produkte = shop.SearchProdukt(orgeingabe);
|
|
for(int i = 0; i < produkte.size(); i++) {
|
|
System.out.println("id: "+produkte.get(i)[0]);
|
|
System.out.println("Name: "+produkte.get(i)[1]);
|
|
System.out.println("Gewicht: "+produkte.get(i)[2]+"g");
|
|
System.out.println("Nettopreis: "+produkte.get(i)[3]+"ct");
|
|
System.out.println("MwStSatz: "+produkte.get(i)[4]+"%");
|
|
System.out.println("Lagerbestand: "+produkte.get(i)[5]);
|
|
System.out.println("");
|
|
}
|
|
};
|
|
private static void AddProdukt(){
|
|
System.out.println("Bitte geben Sie die id des Produktes ein:");
|
|
String orgeingabe = sc.nextLine();
|
|
int id = Integer.parseInt(orgeingabe);
|
|
for(int i = 0; i<orgeingabe.length();i++) {
|
|
if(!(orgeingabe.charAt(i)>='0'&&orgeingabe.charAt(i)<='9')) {
|
|
return;
|
|
}
|
|
}
|
|
System.out.println("Bitte geben Sie die Anzahl an:");
|
|
orgeingabe = sc.nextLine();
|
|
int count = Integer.parseInt(orgeingabe);
|
|
for(int i = 0; i<orgeingabe.length();i++) {
|
|
if(orgeingabe.charAt(i)=='-')
|
|
continue;
|
|
if(!(orgeingabe.charAt(i)>='0'&&orgeingabe.charAt(i)<='9')) {
|
|
return;
|
|
}
|
|
}
|
|
shop.AddProduktZuWarenkorb(id,count);
|
|
};
|
|
private static void ShowWarenkorb(){
|
|
ArrayList<String[]> produkte = shop.ShowWarenkorb();
|
|
for(int i = 1; i < produkte.size(); i++) {
|
|
System.out.println("id: "+produkte.get(i)[0]);
|
|
System.out.println("Name: "+produkte.get(i)[1]);
|
|
System.out.println("Nettopreis: "+produkte.get(i)[2]+"ct");
|
|
System.out.println("MwStSatz: "+produkte.get(i)[3]+"%");
|
|
System.out.println("Anzahl im Warenkorb: "+produkte.get(i)[4]);
|
|
System.out.println("");
|
|
}
|
|
|
|
System.out.println("Name: "+produkte.get(0)[0]);
|
|
System.out.println("Adresse: "+produkte.get(0)[1]);
|
|
System.out.println("Netto: "+produkte.get(0)[2]+"ct");
|
|
System.out.println("Netto Versandkosten: "+produkte.get(0)[3]+"ct");
|
|
System.out.println("Netto gesamt: "+produkte.get(0)[4]+"ct");
|
|
System.out.println("Brutto: "+produkte.get(0)[5]+"ct");
|
|
System.out.println("Brutto Versandkosten: "+produkte.get(0)[6]+"ct");
|
|
System.out.println("Brutto gesamt: "+produkte.get(0)[7]+"ct");
|
|
};
|
|
private static void ResetWarenkorb(){
|
|
shop.ResetWarenkorb();
|
|
};
|
|
private static void UpdateKundeInWarenkorb(){
|
|
System.out.println("Bitte schreiben Sie ihren Namen:");
|
|
String name = sc.nextLine();
|
|
System.out.println("Bitte schreiben Sie ihre Addresse:");
|
|
String addr = sc.nextLine();
|
|
shop.UpdateKundeInWarenkorb(name, addr);
|
|
};
|
|
private static void Bestellen() {
|
|
System.out.println("Deine Bestellung mit folgendem Inhalt wurde aufgegeben:");
|
|
ShowWarenkorb();
|
|
shop.AddBestellung();
|
|
System.out.println("");
|
|
System.out.println("");
|
|
System.out.println("Sie können eine weitere Bestellung aufgeben.");
|
|
};
|
|
private static void ShowBestellungen(){ };
|
|
|
|
|
|
private static ArrayList<String> readFile(String path) throws FileNotFoundException {
|
|
ArrayList<String> lines = new ArrayList<>();
|
|
Scanner sc = new Scanner(new File(path));
|
|
while (sc.hasNextLine()) {
|
|
lines.add(sc.nextLine());
|
|
}
|
|
sc.close();
|
|
return lines;
|
|
}
|
|
}
|