209 lines
7.1 KiB
Java
209 lines
7.1 KiB
Java
package pack;
|
|
|
|
import java.io.FileNotFoundException;
|
|
import java.util.ArrayList;
|
|
import java.util.Scanner;
|
|
|
|
|
|
|
|
public class ShopTUI {
|
|
private static OnlineShop shop;
|
|
static Scanner sc = new Scanner(System.in);
|
|
Warenkorb wk = new Warenkorb();
|
|
|
|
public void main(String[] args) throws FileNotFoundException {
|
|
IO.println();
|
|
System.out.println(">>>>>>>>>>Willkommen zum DanDan-Shop!<<<<<<<<<<");
|
|
shop= new OnlineShop();
|
|
boolean cont = true;
|
|
|
|
while (cont) {
|
|
cont = hauptmenü();
|
|
}
|
|
|
|
System.out.println("Auf Wiedersehen!");
|
|
sc.close();
|
|
}
|
|
|
|
public boolean hauptmenü() throws FileNotFoundException {
|
|
|
|
IO.println();
|
|
IO.println(" << H a u p t m e n ü >> ");
|
|
IO.println("1.Produktangebot");
|
|
IO.println("2.Produktsuche");
|
|
IO.println("3.Warenkorb-Menü(hierüber Produkte Hinzufügen)");
|
|
IO.println("4. Bestellungen");
|
|
IO.println("5. Exit ");
|
|
IO.print(">>");
|
|
String eingabe = sc.nextLine();
|
|
switch (eingabe) {
|
|
case "1": case "produktangebot": case "Produktangebot": case "Angebot": case "angebot":
|
|
produktangebot();
|
|
break;
|
|
case "2": case "suche": case "Suche": case"produktsuche":
|
|
produktsuche();
|
|
break;
|
|
case "3": case "warenkorb": case"Warenkorb":
|
|
MeinWarenkorb();
|
|
break;
|
|
case "4": case "bestellungen": case"Bestellungen":
|
|
bestellen();
|
|
break;
|
|
case "5": case "exit " : case "Exit":
|
|
return false;
|
|
|
|
default:
|
|
IO.println("Etwas ist schiefgelaufen, probieren sie es nochmal");
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public static void produktangebot() throws FileNotFoundException {
|
|
System.out.println("Unser Produktangebot:");
|
|
String[][] produkt = shop.Start();
|
|
|
|
IO.println();
|
|
for (int i = 0; i < produkt.length; i++) {
|
|
for (int j = 0; j < produkt[i].length; j++) {
|
|
String helpString = produkt[i][j];
|
|
int length = 10;
|
|
if (j == 1)
|
|
length = 25;
|
|
while (helpString.length() != length) {
|
|
helpString += " ";
|
|
}
|
|
|
|
IO.print(helpString);
|
|
IO.print(" | ");
|
|
}
|
|
IO.println();
|
|
}//TOD= vlt hier auch hinzufügen aufrufwn
|
|
|
|
} public static void produktsuche() throws FileNotFoundException {
|
|
IO.print("Ich suche: ");
|
|
String suche = sc.nextLine();
|
|
int count=0;
|
|
Produkt vlt=null;
|
|
// boolean[] aufLager= shop.aufLager();
|
|
ArrayList<Produkt> ProduktListe= shop.ÜbertrageListe();
|
|
IO.println();
|
|
Produkt gefunden= shop.suchProdukt(suche);
|
|
if(gefunden==null) {
|
|
for(int i=0;i<ProduktListe.size();i++) {
|
|
for (int j = 0; j < 5&& j<ProduktListe.get(i).name.length(); j++) {
|
|
if (suche.charAt(j) == (ProduktListe.get(i).name).charAt(j)){ //Todo gucken warum Ignore.Case nicht klappt
|
|
count++;
|
|
if(count==4){
|
|
vlt=ProduktListe.get(i);
|
|
}
|
|
}else {
|
|
continue;
|
|
}
|
|
} count=0;
|
|
}
|
|
if(vlt.name.length()>4) {
|
|
IO.println("Meinten Sie vielleicht "+ vlt.name + " " +vlt.preis+ "€ ?");
|
|
IO.println("Unser Bestand beträgt "+ vlt.Bestand);//TODO hinzufügen ermöglichen
|
|
}else
|
|
IO.println("Das gesuchte Produkt wurde leider nicht gefunden");
|
|
} else {
|
|
IO.println("Hier ist das Produkt: " + gefunden.name + " " + gefunden.preis + " € zzgl. " + gefunden.mwst+" % mwst");
|
|
if(gefunden.Bestand ==0){
|
|
IO.println("Das Produkt ist aber leider zur Zeit nicht verfügbar");
|
|
//Todo hier trimen oder splite damit der user nicht sowas wie 7l hinzufügen muss
|
|
}else
|
|
IO.println("Wollen sie das Produkt zum Warenkorb hinzufügen?");
|
|
//Todo hinzufügfen ermöglichen
|
|
|
|
}
|
|
|
|
}
|
|
public void bestellen(){
|
|
//Hier alle infos wie name und addresse abfangen
|
|
}
|
|
|
|
public void MeinWarenkorb() throws FileNotFoundException {
|
|
Warenkorb warenkorb;
|
|
String Wahl;
|
|
do {
|
|
IO.println(">>Warenkorb-Menü<<");
|
|
IO.println("1. Artikel hinzüfugen [Bitte hierfür am besten die Produkt ID benutzen!]");
|
|
IO.println("2. Meinen Warenkorb anzeigen ");
|
|
IO.println("3. Etwas aus den Warenkorb löschen");
|
|
IO.println("4. Die Menge reduzieren");
|
|
IO.println("5. back");
|
|
IO.print(">>");
|
|
Wahl = sc.nextLine();
|
|
switch (Wahl) {
|
|
case "1":
|
|
hinzufuegen();
|
|
break;
|
|
case "2":
|
|
warenkorbAnzeigen();
|
|
break;
|
|
case "3":
|
|
artikelLöschen();
|
|
break;
|
|
case "4":
|
|
mengeReduzieren();
|
|
break;
|
|
|
|
|
|
}
|
|
} while (!Wahl.equals("5")||Wahl.equalsIgnoreCase("back"));
|
|
|
|
|
|
} public void hinzufuegen() throws FileNotFoundException {
|
|
IO.println("Bitte geben sie eine ProduktID ein");
|
|
IO.print("ID:");
|
|
int ID=sc.nextInt();
|
|
IO.println("Wieviel wollen sie hinzufügen?");
|
|
IO.print("Menge:");
|
|
int Menge=sc.nextInt();
|
|
sc.nextLine();
|
|
boolean geklappt= wk.ProduktDa(ID,Menge);
|
|
if(geklappt){
|
|
IO.println("Das Produkt wurde zum Warenkorb hinzugefügt!!");
|
|
}else
|
|
IO.println("Die ID existiert nicht oder das Produkt ist leider nicht auf Lager");
|
|
|
|
}
|
|
public void warenkorbAnzeigen() {
|
|
IO.println("====Mein Warenkorb====");
|
|
ArrayList<WarenkorbArtikel> Artikel=wk.ÜbertrageArtikel();
|
|
//ArrayList<WarenkorbArtikel> warenkorb = new ArrayList<>(); //Mit KI,siehe (1)[ // Ergänzung Fehler von der KI selber korrigiert
|
|
|
|
for (WarenkorbArtikel artikel : Artikel) {
|
|
System.out.println(artikel); //bis hier KI
|
|
}
|
|
|
|
|
|
|
|
}
|
|
public void artikelLöschen() {
|
|
IO.println("Geben sie die ID des Produktes welches sie entfernen wollen ein");
|
|
IO.print("ID");
|
|
int ID=sc.nextInt();
|
|
sc.nextLine();
|
|
wk.entferneArtikel(ID);
|
|
IO.println("Sollte der Artikel im Warenkorb gewesen sein, wurde er entfernt");
|
|
}
|
|
public void mengeReduzieren() {
|
|
IO.println("Geben sie die ID von dem Produkt an, dessen Menge sie reduzieren wollen");
|
|
IO.print("ID");
|
|
IO.println();
|
|
int ID=sc.nextInt();
|
|
sc.nextLine();
|
|
IO.println("Um wieviel wollen sie die Anzahl reduzieren?");
|
|
IO.print("um:");
|
|
int red=sc.nextInt();
|
|
sc.nextLine();
|
|
wk.andereMenge(ID,red);
|
|
IO.println();
|
|
IO.println("Die Menge wurde reduziert");
|
|
|
|
|
|
}
|
|
|
|
} |