Online-Shop/Shop.java

148 lines
6.2 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package Shop;
import Shop.OnlineShop;
import Shop.Products;
import Shop.Cart;
import java.util.Scanner;
import java.io.FileNotFoundException;
public class Shop {
private static OnlineShop shop;
static Cart cart = new Cart();
private static Scanner sc = new Scanner(System.in);
public static void main(String[] args) throws FileNotFoundException {
System.out.println("Willkommen bei Blümchen, Ihrem Vertrieber für AlltagsProdukte");
shop = new OnlineShop();
cart = new Cart();
cart = new Cart();
mainMenu();
}
public static void mainMenu() {
System.out.println("\n 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.print("Bitte geben Sie eine der Optionen an: ");
String eingabe = sc.nextLine().toLowerCase();
if (eingabe.equals("produktangebot") || eingabe.equals("angebot")) {
Sale();
} else if (eingabe.equals("produktsuche") || eingabe.equals("suche")) {
Search();
} else if (eingabe.equals("warenkorb")) {
Cart();
} else if (eingabe.equals("beenden")) {
System.out.println(" ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄");
System.out.println(" Auf Wiedersehen! ");
System.out.println("____________________________");
} else {
System.out.println("\n\n Ungültige Eingabe (˃̣̣̥ᯅ˂̣̣̥) Versuchen Sie es bitte erneut:");
mainMenu();
}
}
public static void Sale() {
System.out.println("\n\n\n Produkte: \n");
Products[] produkte = shop.ProductList();
for (int i = 0; i < produkte.length; i++) {
Products prod = shop.warehouse.get(i);
System.out.printf(prod.getProductID(), prod.getName(), prod.getGrossPrice());
}
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 Input = sc.nextLine().toLowerCase();
if (Input.equals("hauptmenü")) {
mainMenu();
}
int nums = Integer.parseInt(Input);
int index = nums - 1;
Products prod = shop.warehouse.get(index);
System.out.println("\n\n\nSie haben folgendes ausgewählt: " + prod.getName());
System.out.println("\n\n\nSie haben folgendes ausgewählt: " + prod.getName());
System.out.println("Geben Sie bitte die gewünschte Menge an: \n");
int menge = Integer.parseInt(sc.nextLine());
if (menge <= prod.getStock()) {
Cart.AddCart(prod, menge);
System.out.println("Das Produkt wurde in der gewünschten Menge zum Warenkorb hinzugefügt ");
} else {
System.out.println("Leider ist das gewünschte Produkt nicht in dieser quantität verfügbar");
}
System.out.println("Zurück zum Hauptmenü.");
mainMenu();
}
public static void Search() {
System.out.println("Wonach suchen Sie?: ");
String suchbegriff = sc.nextLine().toLowerCase();
if (suchbegriff.length() == 0)
return;
if (suchbegriff.equals("hauptmenü"))
return;
boolean found = false;
for (int artnr = 0; artnr < shop.warehouse.size(); artnr++) {
Products products = shop.warehouse.get(artnr);
for (int i = 0; i <= products.getName().length() - suchbegriff.length(); i++) {
if (products.getName().substring(i, i + suchbegriff.length()).toLowerCase().equals(suchbegriff)) {
for (int j = 0; j <= products.getName().length() - suchbegriff.length(); j++) {
if (products.getName().substring(i, i + suchbegriff.length()).toLowerCase().equals(suchbegriff)) {
if (!found) {
System.out.println("Treffer: ");
}
System.out.println(products);
found = true;
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 amount = Integer.parseInt(sc.nextLine());
if (amount <= products.getStock()) {
Cart.AddCart(products, amount);
System.out.println("Das Produkt wurde in der gewünschten Menge zum Warenkorb hinzugefügt, Sie werden zum Hauptmenü zurückgeleitet");
mainMenu();
}
else {
System.out.println("Leider ist das gewünschte Produnkt nicht in der Quantität vorhanden Sie werden zum Hauptmenü zurückgeleitet");
mainMenu();
}
}
}
}
}
if (!found) {
System.out.println("Keine Treffer,Sie werden zum Hauptmenü umgeleitet");
mainMenu();
}
}
}
}
}