+ Bestellen
+ Warenkorb wird geleert und weiter geeinkaufen + Menge der Positionen im Warenkorb bearbeitenmain
parent
1ba04f5320
commit
37509ec232
|
|
@ -29,10 +29,8 @@ public class OnlineShop {
|
|||
|
||||
Produkt p = new Produkt(id, name, gewicht, preis, mwst, bestand);
|
||||
|
||||
lager.add(p);
|
||||
|
||||
lager.add(p);
|
||||
}
|
||||
|
||||
sc.close();
|
||||
}
|
||||
|
||||
|
|
@ -41,7 +39,29 @@ public class OnlineShop {
|
|||
for(int i = 0; i < lager.size(); i++) {
|
||||
produkt[i] = lager.get(i).toString();
|
||||
}
|
||||
|
||||
return produkt;
|
||||
}
|
||||
|
||||
|
||||
public boolean reduzieren(Produkt p, int menge) {
|
||||
for (Produkt lagerProdukt : lager) {
|
||||
if (lagerProdukt.equals(p)) {
|
||||
if (lagerProdukt.bestand >= menge) {
|
||||
lagerProdukt.bestand -= menge;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void erhöhen(Produkt p, int menge) {
|
||||
for (Produkt lagerProdukt : lager) {
|
||||
if (lagerProdukt.equals(p)) {
|
||||
lagerProdukt.bestand += menge;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package backend;
|
|||
import java.util.ArrayList;
|
||||
|
||||
public class Warenkorb {
|
||||
public ArrayList<Produkt> inhalt;
|
||||
private ArrayList<Produkt> inhalt;
|
||||
private ArrayList<WarenkorbPosition> positionen;
|
||||
|
||||
public Warenkorb() {
|
||||
|
|
@ -33,19 +33,43 @@ public class Warenkorb {
|
|||
}
|
||||
|
||||
|
||||
public double berechneGesamtpreis() {
|
||||
double preis = 0;
|
||||
for (Produkt p : inhalt)
|
||||
preis+= p.preis;
|
||||
return preis;
|
||||
}
|
||||
public double berechneGesamtpreis() {
|
||||
double preis = 0;
|
||||
for (WarenkorbPosition wp : positionen) {
|
||||
preis += wp.getMenge() * wp.getProdukt().getPreis();
|
||||
}
|
||||
return preis;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void bestellungSicht() {
|
||||
|
||||
public void pEntfernen(Produkt p) {
|
||||
ArrayList<WarenkorbPosition> neu = new ArrayList<>();
|
||||
for (WarenkorbPosition wp : positionen) {
|
||||
System.out.println(wp.getMenge() + "x " + wp.getProdukt().getName() + " - " + wp.getProdukt().getPreis() + "€");
|
||||
if (!wp.getProdukt().equals(p)) {
|
||||
neu.add(wp);
|
||||
} else {
|
||||
p.bestand += wp.getMenge();
|
||||
}
|
||||
}
|
||||
positionen = neu;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean mengeAendern(Produkt p, int neu) {
|
||||
if (neu == 0) {
|
||||
this.pEntfernen(p);
|
||||
return true;
|
||||
}
|
||||
|
||||
for (WarenkorbPosition wp : positionen) {
|
||||
if (wp.getProdukt().equals(p)) {
|
||||
wp.setMenge(neu);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ package backend;
|
|||
|
||||
public class WarenkorbPosition {
|
||||
|
||||
public Produkt produkt;
|
||||
public int menge;
|
||||
private Produkt produkt;
|
||||
private int menge;
|
||||
|
||||
public WarenkorbPosition(Produkt produkt, int menge) {
|
||||
this.produkt = produkt;
|
||||
|
|
@ -17,7 +17,6 @@ public class WarenkorbPosition {
|
|||
public int getMenge() {
|
||||
return menge;
|
||||
}
|
||||
|
||||
|
||||
public void setMenge(int menge) {
|
||||
this.menge = menge;
|
||||
|
|
|
|||
|
|
@ -10,18 +10,22 @@ import java.io.FileNotFoundException;
|
|||
public class shopTUI {
|
||||
|
||||
private static OnlineShop shop;
|
||||
public static Warenkorb warenkorb = new Warenkorb();
|
||||
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("\n ⋆ ˚。⋆ Hauptmenü ⋆ ˚。⋆ ");
|
||||
System.out.println(" ⏔⏔⏔⏔⏔⏔⏔ ꒰ ᧔ෆ᧓ ꒱ ⏔⏔⏔⏔⏔⏔⏔ ");
|
||||
System.out.println(" Produktangebot ");
|
||||
System.out.println(" Produktsuche ");
|
||||
|
|
@ -29,43 +33,41 @@ public class shopTUI {
|
|||
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")) {
|
||||
if (eingabe.equals("produktangebot") || eingabe.equals("angebot")) {
|
||||
angebot();
|
||||
} else if (eingabe.equals("produktsuche")) {
|
||||
} else if (eingabe.equals("produktsuche") || eingabe.equals("suche")) {
|
||||
suche();
|
||||
} else if (eingabe.equals("warenkorb")) {
|
||||
warenkorbAnzeigen();
|
||||
} 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(" \\ / ");
|
||||
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: ");
|
||||
System.out.println("\n\n Ungültige Eingabe (˃̣̣̥ᯅ˂̣̣̥) Versuchen Sie es bitte erneut:");
|
||||
hauptmenü();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void angebot() {
|
||||
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("%-3d | %-25s | %.2f€\n", p.id, p.name, p.preis);
|
||||
System.out.printf(" %-2d | %-23s | %.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: ");
|
||||
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ü();
|
||||
return;
|
||||
}
|
||||
|
||||
int nummer = Integer.parseInt(eingabe);
|
||||
|
|
@ -77,7 +79,7 @@ public class shopTUI {
|
|||
int menge = Integer.parseInt(sc.nextLine());
|
||||
if (menge <= p.bestand) {
|
||||
warenkorb.produktHinzufügen(p, menge);
|
||||
p.bestand -= 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 (˃̣̣̥ᯅ˂̣̣̥)");
|
||||
|
|
@ -86,6 +88,7 @@ public class shopTUI {
|
|||
hauptmenü();
|
||||
}
|
||||
|
||||
|
||||
public static void suche() {
|
||||
System.out.println("\n(˶˃ᵕ˂˶) Wonach suchen Sie?: ");
|
||||
String suchbegriff = sc.nextLine().toLowerCase();
|
||||
|
|
@ -108,16 +111,17 @@ public class shopTUI {
|
|||
|
||||
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;
|
||||
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ü();
|
||||
hauptmenü();
|
||||
} else {
|
||||
System.out.println("Leider reicht unser Bestand nicht aus (˃̣̣̥ᯅ˂̣̣̥)");
|
||||
System.out.println("Ab zum Hauptmenü... ٩(^ᗜ^ )و \n\n\n");
|
||||
|
|
@ -136,22 +140,31 @@ public class shopTUI {
|
|||
hauptmenü();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void warenkorbAnzeigen() {
|
||||
if (warenkorb.getPositionen().size() == 0) {
|
||||
System.out.println("\n\nIhr Warenkorb ist leer (˶ᵕ˶)⸝♡");
|
||||
System.out.println("Ab zum Hauptmenü... ٩(^ᗜ^ )و \n\n\n");
|
||||
hauptmenü();
|
||||
hauptmenü();
|
||||
} else {
|
||||
System.out.println("\n\n(。•◡•。) Hier ist Ihr aktueller Warenkorb: ");
|
||||
int pos = 1;
|
||||
for (WarenkorbPosition wp : warenkorb.getPositionen()) {
|
||||
System.out.println(wp.getMenge() + "x | " + wp.getProdukt().getName() + " | " + wp.getProdukt().getPreis() + "€");
|
||||
System.out.printf("Pos.: %2d. | %dx | %-23s | %.2f€\n",
|
||||
pos++,
|
||||
wp.getMenge(),
|
||||
wp.getProdukt().getName(),
|
||||
wp.getProdukt().getPreis());
|
||||
}
|
||||
System.out.printf("Ihre Summe beträgt %.1f€ ૮˶ᵔᵕᵔ˶ა%n", warenkorb.berechneGesamtpreis());
|
||||
System.out.println("\n\n\nMöchten Sie bestellen oder zurück zum Hauptmenü?: ");
|
||||
System.out.printf("Ihre Summe beträgt %.2f€ ૮˶ᵔᵕᵔ˶ა%n", warenkorb.berechneGesamtpreis());
|
||||
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ü")) {
|
||||
if (eingabe.equals("hauptmenü") || eingabe.equals("menü")) {
|
||||
hauptmenü();
|
||||
} else if (eingabe.equals("menge ändern") || eingabe.equals("die menge ändern") || eingabe.equals("ändern")) {
|
||||
mengeBearbeiten();
|
||||
} else if (eingabe.equals("bestellen")) {
|
||||
System.out.print("Bitte geben Sie Ihren vollständigen Namen ein: ");
|
||||
String name = sc.nextLine();
|
||||
|
|
@ -164,13 +177,60 @@ public class shopTUI {
|
|||
System.out.println("━O━O━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
|
||||
System.out.println("Name: ");
|
||||
System.out.println(name);
|
||||
System.out.println("Adresse: ");
|
||||
System.out.println("\nAdresse: ");
|
||||
System.out.println(adresse);
|
||||
System.out.println("Artikel:" );
|
||||
warenkorb.bestellungSicht();
|
||||
System.out.println("\nArtikel:" );
|
||||
int artpos = 1;
|
||||
for (WarenkorbPosition wp : warenkorb.getPositionen()) {
|
||||
System.out.printf("Pos.: %2d. | %d | %-23s | %.2f€\n",
|
||||
artpos++,
|
||||
wp.getMenge(),
|
||||
wp.getProdukt().getName(),
|
||||
wp.getProdukt().getPreis());
|
||||
}
|
||||
System.out.println("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
|
||||
warenkorb = new Warenkorb();
|
||||
System.out.println("\n\nIhr Warenkorb wurde geleert! ◝(˶˃ᵕ˂˶)◜");
|
||||
System.out.println("Ab zum Hauptmenü... ٩(^ᗜ^ )و \n\n\n");
|
||||
hauptmenü();
|
||||
} else {
|
||||
System.out.println("\n\n Ungültige Eingabe (˃̣̣̥ᯅ˂̣̣̥) Versuchen Sie es bitte erneut: \n\n");
|
||||
warenkorbAnzeigen();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void mengeBearbeiten() {
|
||||
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:");
|
||||
warenkorbAnzeigen();
|
||||
return;
|
||||
}
|
||||
|
||||
WarenkorbPosition wp = warenkorb.getPositionen().get(posNr);
|
||||
Produkt p = wp.getProdukt();
|
||||
int alt = wp.getMenge();
|
||||
|
||||
System.out.print("\nGeben Sie bitte die neue Menge: ");
|
||||
int neu = Integer.parseInt(sc.nextLine());
|
||||
int x = neu - alt;
|
||||
|
||||
if (neu == 0) {
|
||||
warenkorb.pEntfernen(p);
|
||||
System.out.println("Die Position wurde gelöscht! ✧。٩(ˊᗜˋ)و✧*。");
|
||||
} else if (x > 0 && p.bestand < 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! ✧。٩(ˊᗜˋ)و✧*。");
|
||||
}
|
||||
|
||||
warenkorbAnzeigen();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue