From d0b44937555b69b89e4faee56fed9d2485180642 Mon Sep 17 00:00:00 2001 From: Dima Date: Thu, 12 Dec 2024 19:30:52 +0100 Subject: [PATCH] Bestellungen: Bestand wird aktualisiert --- Restaurantverwaltung/src/Bestellsystem.java | 20 +++++-- Restaurantverwaltung/src/Bestellungen.txt | 12 ++++ Restaurantverwaltung/src/Inventory.java | 14 +++-- Restaurantverwaltung/src/Menu.java | 55 ++++++++++++------- .../src/SystemController.java | 4 +- Restaurantverwaltung/src/stock.txt | 11 ++-- 6 files changed, 80 insertions(+), 36 deletions(-) diff --git a/Restaurantverwaltung/src/Bestellsystem.java b/Restaurantverwaltung/src/Bestellsystem.java index b54ac2f..114edac 100644 --- a/Restaurantverwaltung/src/Bestellsystem.java +++ b/Restaurantverwaltung/src/Bestellsystem.java @@ -10,6 +10,7 @@ import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; import java.util.HashMap; + public class Bestellsystem { private static List bestellungen = new ArrayList<>(); @@ -50,16 +51,24 @@ public class Bestellsystem { boolean istVerfuegbar = false; if (gericht.equalsIgnoreCase("fertig")) { speichereBestellung(bestellung); + System.out.println("Bestand wurde aktualisiert"); break; } - for (Dish dish : menu.getDishes()) { + try { for (Dish dish : menu.getDishes()) { if (gericht.equalsIgnoreCase(dish.getName())) { + SystemController.inventory.useIngredients(dish.getIngredients()); bestellung.addGericht(gericht); istVerfuegbar = true; bestellungen.add(bestellung); System.out.println("Bestellung wurde aktualisiert"); System.out.println(bestellung.getBestellungDetails()); - } + + } + // else { +// System.out.println("Ist nicht verfügbar"); +// } + }} catch (Exception e ) { + } if (istVerfuegbar == false) { System.out.println("Gericht ist nicht im Menu"); @@ -77,6 +86,7 @@ public class Bestellsystem { // break; // } // } + } } @@ -86,9 +96,9 @@ public class Bestellsystem { File file = new File("src/Bestellungen.txt"); FileWriter writer = new FileWriter(file, true); writer.write(bestellung.getBestellungDetails()); - LocalTime now = LocalTime.now(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm"); - writer.write("\nZeit: " + now.format(formatter)); + LocalTime now = LocalTime.now(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm"); + writer.write("\nZeit: " + now.format(formatter)); writer.write("\n--------------------------\n"); writer.close(); System.out.println("Bestellung wurde erfolgreich gespeichert."); diff --git a/Restaurantverwaltung/src/Bestellungen.txt b/Restaurantverwaltung/src/Bestellungen.txt index e69de29..df8dc64 100644 --- a/Restaurantverwaltung/src/Bestellungen.txt +++ b/Restaurantverwaltung/src/Bestellungen.txt @@ -0,0 +1,12 @@ +Tisch Nummer: 4444 +Bestellte Gerichte: + +Zeit: 18:58 +-------------------------- +Tisch Nummer: 3333 +Bestellte Gerichte: +- Ayrimramen +- Cheeseburger + +Zeit: 19:12 +-------------------------- diff --git a/Restaurantverwaltung/src/Inventory.java b/Restaurantverwaltung/src/Inventory.java index 85d7ade..ba6ff17 100644 --- a/Restaurantverwaltung/src/Inventory.java +++ b/Restaurantverwaltung/src/Inventory.java @@ -33,7 +33,6 @@ class Inventory { writer.write(entry.getKey() + "," + entry.getValue()); writer.newLine(); } - System.out.println("Bestand in Datei gespeichert."); } catch (IOException e) { System.out.println("Fehler beim Speichern der Datei: " + e.getMessage()); } @@ -49,8 +48,8 @@ class Inventory { System.out.println(entry.getKey() + ": " + entry.getValue()); } } - - public boolean useIngredients(Map ingredients) { + + public boolean showIngredientsAvailable(Map ingredients) { for (Map.Entry entry : ingredients.entrySet()) { String ingredient = entry.getKey(); int amount = entry.getValue(); @@ -59,10 +58,17 @@ class Inventory { return false; } } + + return true; + } + + public void useIngredients(Map ingredients) { + for (Map.Entry entry : ingredients.entrySet()) { stock.put(entry.getKey(), stock.get(entry.getKey()) - entry.getValue()); + saveStockToFile(); } - return true; + } // Neue Methode: Zutaten hinzufügen diff --git a/Restaurantverwaltung/src/Menu.java b/Restaurantverwaltung/src/Menu.java index 0563cb5..9b063e0 100644 --- a/Restaurantverwaltung/src/Menu.java +++ b/Restaurantverwaltung/src/Menu.java @@ -1,28 +1,43 @@ import java.util.*; + class Menu { - public List dishes = new ArrayList<>(); + public List dishes = new ArrayList<>(); + public List availableDishes = new ArrayList<>(); - public Menu() { + public Menu() { - dishes.add(new Dish("Cheeseburger", Map.of("Brot", 1, "Fleisch", 1, "Käse", 1))); - dishes.add(new Dish("Veggie-Burger", Map.of("Brot", 1, "Salat", 1, "Tomaten", 1))); - dishes.add(new Dish("Double Meat Burger", Map.of("Brot", 1, "Fleisch", 2))); - } + dishes.add(new Dish("Cheeseburger", Map.of("Brot", 1, "Fleisch", 1, "Käse", 1))); + dishes.add(new Dish("Veggie-Burger", Map.of("Brot", 1, "Salat", 1, "Tomaten", 1))); + dishes.add(new Dish("Double Meat Burger", Map.of("Brot", 1, "Fleisch", 2))); + dishes.add(new Dish("Ramen", Map.of("Soße", 1, "Salat", 1, "Tomaten", 1, "Nudeln", 30))); + } - public void displayMenu(Inventory inventory) { - System.out.println("Verfügbares Menü:"); - for (Dish dish : dishes) { - if (inventory.useIngredients(dish.getIngredients()) == true) { - System.out.println("- " + dish.getName()); - } - } - } + public void displayMenu(Inventory inventory) { + System.out.println("Verfügbares Menü:"); + for (Dish dish : dishes) { + if (inventory.showIngredientsAvailable(dish.getIngredients()) == true) { + System.out.println("- " + dish.getName()); + availableDishes.add(dish); + } + } + } + + public List getAvailableDishes() { + return availableDishes; + } - public List getDishes() { - return dishes; - } + public void bestandMinus(Inventory inventory) { + for (Dish dish : dishes) { + inventory.useIngredients(dish.getIngredients()); - public void setDishes(List dishes) { - this.dishes = dishes; - } + } + } + + public List getDishes() { + return dishes; + } + + public void setDishes(List dishes) { + this.dishes = dishes; + } } \ No newline at end of file diff --git a/Restaurantverwaltung/src/SystemController.java b/Restaurantverwaltung/src/SystemController.java index 9ad2b19..78e077c 100644 --- a/Restaurantverwaltung/src/SystemController.java +++ b/Restaurantverwaltung/src/SystemController.java @@ -7,7 +7,7 @@ class SystemController { private Scanner scanner = new Scanner(System.in); private Map users = new HashMap<>(); private final String USERS_FILE = "src/users.txt"; - private Inventory inventory = new Inventory(); + public static Inventory inventory = new Inventory(); private Menu menu = new Menu(); public SystemController() { @@ -143,8 +143,8 @@ class SystemController { switch (choice) { case 1 -> { menu.displayMenu(inventory); - Bestellsystem.erstelleBestellung(); // Neue Bestellung erstellen + } case 2 -> { Bestellsystem.zeigeAlleBestellungen(); // Bestellungen im Speicher anzeigen diff --git a/Restaurantverwaltung/src/stock.txt b/Restaurantverwaltung/src/stock.txt index 537a4dc..31133c0 100644 --- a/Restaurantverwaltung/src/stock.txt +++ b/Restaurantverwaltung/src/stock.txt @@ -1,6 +1,7 @@ -Soße,50000000 +Soße,49999996 Ananasdasdas,5000 -Brot,1532 -Tomaten,511 -Käse,732 -Fleisch,24 \ No newline at end of file +Brot,1519 +Tomaten,503 +Käse,724 +Fleisch,12 +Salat,494