info-java/Technikladen/TechStore.java

125 lines
3.1 KiB
Java
Raw Normal View History

2024-10-18 15:17:59 +02:00
<<<<<<< HEAD
import java.util.Scanner;
2024-10-15 06:20:09 +02:00
import java.util.ArrayList;
2024-10-18 15:17:59 +02:00
=======
import java.util.ArrayList;
import java.util.Scanner;
2024-10-18 15:17:59 +02:00
>>>>>>> 89bb3a674e4304644c37109ed5a608b97926deb9
public class TechStore {
public static void p(String input) {
System.out.print(input);
}
public static void main(String[] args) {
2024-10-18 15:17:59 +02:00
<<<<<<< HEAD
2024-10-15 06:17:06 +02:00
StorageManager manager = new StorageManager();
OrderSystem system = new OrderSystem(manager);
2024-10-18 15:17:59 +02:00
=======
StorageManager manager = new StorageManager(new ArrayList<Product>());
OrderSystem system = new OrderSystem(manager, new ArrayList<Client>());
2024-10-18 15:17:59 +02:00
>>>>>>> 89bb3a674e4304644c37109ed5a608b97926deb9
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<Client> 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;
}
}
}
}
}
2024-10-18 15:17:59 +02:00
<<<<<<< HEAD
=======
2024-10-18 15:17:59 +02:00
>>>>>>> 89bb3a674e4304644c37109ed5a608b97926deb9