+ 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ügenmain
parent
fba7b85542
commit
e0281db2c0
|
|
@ -8,9 +8,11 @@ public class Warenkorb {
|
|||
inhalt = new ArrayList<Produkt>();
|
||||
}
|
||||
|
||||
public void produktHinzufügen(Produkt p) {
|
||||
public void produktHinzufügen(Produkt p, int menge) {
|
||||
for (int i = 0; i < menge; i++) {
|
||||
inhalt.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
public double berechneGesamtpreis() {
|
||||
double preis = 0;
|
||||
|
|
@ -20,9 +22,22 @@ public class Warenkorb {
|
|||
}
|
||||
|
||||
public void anzeigen() {
|
||||
if (inhalt.size() == 0) {
|
||||
System.out.println();
|
||||
System.out.println();
|
||||
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)
|
||||
for (Produkt p : inhalt) {
|
||||
System.out.println(p);
|
||||
System.out.println("Betrag: " + berechneGesamtpreis() + "€ ૮˶ᵔᵕᵔ˶ა");
|
||||
System.out.println("Ihre Summe beträgt " + berechneGesamtpreis() + "€ ૮˶ᵔᵕᵔ˶ა");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package tui;
|
||||
import backend.OnlineShop;
|
||||
import backend.Produkt;
|
||||
import backend.Warenkorb;
|
||||
import java.util.Scanner;
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
|
|
@ -8,43 +9,90 @@ import java.io.FileNotFoundException;
|
|||
public class shopTUI {
|
||||
|
||||
private static OnlineShop shop;
|
||||
public 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();
|
||||
|
||||
angebot();
|
||||
|
||||
suche();
|
||||
|
||||
System.out.println("Auf Wiedersehen! (づ˶•༝•˶)づ ");
|
||||
hauptmenü();
|
||||
}
|
||||
|
||||
public static void hauptmenü() {
|
||||
// TODO: hier ein erstes Menü mit bspw.
|
||||
// Produktangebot
|
||||
// Produktsuche
|
||||
// Warenkorbanzeige
|
||||
// evtl. Bestellung (kann auch über Warenkorb realisiert werden)
|
||||
// Exit
|
||||
System.out.println();
|
||||
System.out.println(" ⋆ ˚。⋆ Hauptmenü ⋆ ˚。⋆ ");
|
||||
System.out.println(" ⏔⏔⏔⏔⏔⏔⏔ ꒰ ᧔ෆ᧓ ꒱ ⏔⏔⏔⏔⏔⏔⏔ ");
|
||||
System.out.println(" Produktangebot ");
|
||||
System.out.println(" Produktsuche ");
|
||||
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() {
|
||||
System.out.println("૮ ྀིᴗ͈.ᴗ͈ ྀིა Was wir Ihnen anbieten:");
|
||||
System.out.println();
|
||||
|
||||
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++)
|
||||
System.out.println(produkte[i]);
|
||||
for (int i = 0; i < produkte.length; 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() {
|
||||
System.out.println();
|
||||
System.out.println("(˶˃ᵕ˂˶) Was suchen Sie? ");
|
||||
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;
|
||||
|
||||
|
|
@ -54,16 +102,39 @@ public class shopTUI {
|
|||
for (int i = 0; i <= p.name.length() - suchbegriff.length(); i++) {
|
||||
if (p.name.substring(i, i + suchbegriff.length()).toLowerCase().equals(suchbegriff)) {
|
||||
if(!gefunden) {
|
||||
System.out.println();
|
||||
System.out.println();
|
||||
System.out.println("(˶ˆᗜˆ˵) Wir haben folgenden Treffer: ");
|
||||
System.out.println("\n(˶ˆᗜˆ˵) Wir haben folgenden Treffer zu bieten: ");
|
||||
}
|
||||
System.out.println(p);
|
||||
gefunden = true;
|
||||
break;
|
||||
|
||||
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.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 (˃̣̣̥ᯅ˂̣̣̥)");
|
||||
}
|
||||
if (!gefunden) {
|
||||
System.out.println("Leider keine Treffer (˃̣̣̥ᯅ˂̣̣̥)");
|
||||
System.out.println("Ab zum Hauptmenü... ٩(^ᗜ^ )و \n\n\n");
|
||||
hauptmenü();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue