diff --git a/Technikladen/TechStore.java b/Technikladen/TechStore.java index f8229d0..a11e42a 100755 --- a/Technikladen/TechStore.java +++ b/Technikladen/TechStore.java @@ -1,113 +1,111 @@ -package tech_store; - -import java.util.ArrayList; -import java.util.Scanner; - -public class TechStore { - public static void p(String input) { - System.out.print(input); - } - public static void main(String[] args) { - StorageManager manager = new StorageManager(new ArrayList()); - OrderSystem system = new OrderSystem(manager, new ArrayList()); - Scanner scnr = new Scanner(System.in); - while (true) { - p("\nInput mode: "); - String input = scnr.nextLine(); - if (input.equals("8")) { - break; - } - switch (Integer.parseInt(input)) { - case 1: { - p("Name: "); - String name = scnr.nextLine(); - p("E-Mail: "); - String email = scnr.nextLine(); - system.addClient(new Client(name, email)); - break; - } - case 2: { - ArrayList clients = system.getClients(); - if (clients.isEmpty()) { - System.out.println("No clients found"); - break; - } - for (Client client : clients) { - System.out.println(client.toString()); - } - break; - } - case 3: { - p("ID: "); - int id = Integer.parseInt(scnr.nextLine()); - p("Name: "); - String name = scnr.nextLine(); - p("Price: "); - int price = Integer.parseInt(scnr.nextLine()); - p("Amount: "); - int amt = Integer.parseInt(scnr.nextLine()); - system.addProduct(new Product(id, name, price, amt)); - break; - } - case 4: { - system.showProducts(); - break; - } - case 5: { - system.showProducts(); - p("ID: "); - int id = Integer.parseInt(scnr.nextLine()); - p("Amount: "); - int amt = Integer.parseInt(scnr.nextLine()); - manager.increaseStorage(id, amt); - break; - } - case 6: { - system.showClients(); - p("ID: "); - int clientID = Integer.parseInt(scnr.nextLine()); - p("Date: "); - String date = scnr.nextLine(); - Order order = new Order(clientID, date); - system.showProducts(); - while (true) { - p("ID: "); - String id_str = scnr.nextLine(); - if (id_str.equals("exit")) { - break; - } - int id = Integer.parseInt(id_str); - p("Amount: "); - int amt = Integer.parseInt(scnr.nextLine()); - if (manager.getProductByID(id).getAmount() < amt) { - System.out.println("Amount chosen too high"); - continue; - } - order.addEntry(new OrderEntry(system.getProductByID(id), amt)); - } - system.createOrder(clientID, order); - break; - } - case 7: { - system.showClients(); - p("ID: "); - int id = Integer.parseInt(scnr.nextLine()); - int n = 0; - for (Order order : system.getClientByID(id).getOrders()) { - System.out.println((n++) + order.toString()); - } - p("ID: "); - int order_id = Integer.parseInt(scnr.nextLine()); - System.out.println(system.getClientByID(id).getOrders().get(order_id).createReceipt()); - break; - } - case 8: { - return; - } - } - } - } -} - - - +import java.util.ArrayList; +import java.util.Scanner; + +public class TechStore { + public static void p(String input) { + System.out.print(input); + } + public static void main(String[] args) { + StorageManager manager = new StorageManager(new ArrayList()); + OrderSystem system = new OrderSystem(manager, new ArrayList()); + Scanner scnr = new Scanner(System.in); + while (true) { + p("\nInput mode: "); + String input = scnr.nextLine(); + if (input.equals("8")) { + break; + } + switch (Integer.parseInt(input)) { + case 1: { + p("Name: "); + String name = scnr.nextLine(); + p("E-Mail: "); + String email = scnr.nextLine(); + system.addClient(new Client(name, email)); + break; + } + case 2: { + ArrayList clients = system.getClients(); + if (clients.isEmpty()) { + System.out.println("No clients found"); + break; + } + for (Client client : clients) { + System.out.println(client.toString()); + } + break; + } + case 3: { + p("ID: "); + int id = Integer.parseInt(scnr.nextLine()); + p("Name: "); + String name = scnr.nextLine(); + p("Price: "); + int price = Integer.parseInt(scnr.nextLine()); + p("Amount: "); + int amt = Integer.parseInt(scnr.nextLine()); + system.addProduct(new Product(id, name, price, amt)); + break; + } + case 4: { + system.showProducts(); + break; + } + case 5: { + system.showProducts(); + p("ID: "); + int id = Integer.parseInt(scnr.nextLine()); + p("Amount: "); + int amt = Integer.parseInt(scnr.nextLine()); + manager.increaseStorage(id, amt); + break; + } + case 6: { + system.showClients(); + p("ID: "); + int clientID = Integer.parseInt(scnr.nextLine()); + p("Date: "); + String date = scnr.nextLine(); + Order order = new Order(clientID, date); + system.showProducts(); + while (true) { + p("ID: "); + String id_str = scnr.nextLine(); + if (id_str.equals("exit")) { + break; + } + int id = Integer.parseInt(id_str); + p("Amount: "); + int amt = Integer.parseInt(scnr.nextLine()); + if (manager.getProductByID(id).getAmount() < amt) { + System.out.println("Amount chosen too high"); + continue; + } + order.addEntry(new OrderEntry(system.getProductByID(id), amt)); + } + system.createOrder(clientID, order); + break; + } + case 7: { + system.showClients(); + p("ID: "); + int id = Integer.parseInt(scnr.nextLine()); + int n = 0; + for (Order order : system.getClientByID(id).getOrders()) { + System.out.println((n++) + order.toString()); + } + p("ID: "); + int order_id = Integer.parseInt(scnr.nextLine()); + System.out.println(system.getClientByID(id).getOrders().get(order_id).createReceipt()); + break; + } + case 8: { + return; + } + } + } + } +} + + +