added tech_store
This commit is contained in:
parent
f8e091216c
commit
e51bfa3350
10
Technikladen/.classpath
Normal file
10
Technikladen/.classpath
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
17
Technikladen/.project
Normal file
17
Technikladen/.project
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Technikladen</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
39
Technikladen/Client.java
Executable file
39
Technikladen/Client.java
Executable file
@ -0,0 +1,39 @@
|
||||
package tech_store;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Client {
|
||||
private static int clientCounter;
|
||||
private int clientID;
|
||||
private String clientName;
|
||||
private String clientEmail;
|
||||
private ArrayList<Order> clientOrders;
|
||||
public Client(String clientName, String clientEmail) {
|
||||
clientCounter++;
|
||||
this.clientID = clientCounter;
|
||||
this.clientName = clientName;
|
||||
this.clientEmail = clientEmail;
|
||||
this.clientOrders = new ArrayList<Order>();
|
||||
}
|
||||
public int getID() {
|
||||
return this.clientID;
|
||||
}
|
||||
public String getName() {
|
||||
return this.clientName;
|
||||
}
|
||||
public String getEmail() {
|
||||
return this.clientEmail;
|
||||
}
|
||||
public ArrayList<Order> getOrders() {
|
||||
return this.clientOrders;
|
||||
}
|
||||
public void addOrder(Order order) {
|
||||
this.clientOrders.add(order);
|
||||
}
|
||||
public boolean hasOrder() {
|
||||
return !this.clientOrders.isEmpty();
|
||||
}
|
||||
public String toString() {
|
||||
return ("ID: " + this.clientID + ", Name: " + this.clientName + ", Email: " + this.clientEmail);
|
||||
}
|
||||
}
|
44
Technikladen/Order.java
Executable file
44
Technikladen/Order.java
Executable file
@ -0,0 +1,44 @@
|
||||
package tech_store;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Order {
|
||||
private int orderClientID;
|
||||
private ArrayList<OrderEntry> orderEntries;
|
||||
private String orderDate;
|
||||
public Order(int clientID, String date) {
|
||||
this.orderClientID = clientID;
|
||||
this.orderEntries = new ArrayList<OrderEntry>();
|
||||
this.orderDate = date;
|
||||
}
|
||||
public int getClientID() {
|
||||
return this.orderClientID;
|
||||
}
|
||||
public String getDate() {
|
||||
return this.orderDate;
|
||||
}
|
||||
public ArrayList<OrderEntry> getEntries() {
|
||||
return this.orderEntries;
|
||||
}
|
||||
public void addEntry(OrderEntry entry) {
|
||||
this.orderEntries.add(entry);
|
||||
}
|
||||
public int calcPrice() {
|
||||
int price = 0;
|
||||
for (OrderEntry entry : this.orderEntries) {
|
||||
price += entry.calcPrice();
|
||||
}
|
||||
return price;
|
||||
}
|
||||
public String createReceipt() {
|
||||
String output = "\n";
|
||||
for (OrderEntry entry : this.orderEntries) {
|
||||
output += entry.toString() + ", Price: " + entry.calcPrice() + "\n";
|
||||
}
|
||||
output += "=====" + this.calcPrice() + "=====";
|
||||
return output;
|
||||
}
|
||||
public String toString() {
|
||||
return ("Client: " + this.orderClientID + ", Date: " + this.orderDate);
|
||||
}
|
||||
}
|
16
Technikladen/OrderEntry.java
Executable file
16
Technikladen/OrderEntry.java
Executable file
@ -0,0 +1,16 @@
|
||||
package tech_store;
|
||||
|
||||
public class OrderEntry {
|
||||
private Product orderProduct;
|
||||
private int entryAmount;
|
||||
public OrderEntry(Product product, int amt) {
|
||||
this.orderProduct = product;
|
||||
this.entryAmount = amt;
|
||||
}
|
||||
public int calcPrice() {
|
||||
return this.entryAmount * this.orderProduct.getPrice();
|
||||
}
|
||||
public String toString() {
|
||||
return ("Product: " + this.orderProduct.getName() + ", Amount: " + this.entryAmount);
|
||||
}
|
||||
}
|
57
Technikladen/OrderSystem.java
Executable file
57
Technikladen/OrderSystem.java
Executable file
@ -0,0 +1,57 @@
|
||||
package tech_store;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class OrderSystem {
|
||||
private StorageManager systemManager;
|
||||
private ArrayList<Client> systemClients;
|
||||
public OrderSystem(StorageManager manager, ArrayList<Client> clients) {
|
||||
this.systemManager = manager;
|
||||
this.systemClients = clients;
|
||||
}
|
||||
public void addProduct(Product product) {
|
||||
this.systemManager.addProduct(product);
|
||||
}
|
||||
public void addClient(Client client) {
|
||||
this.systemClients.add(client);
|
||||
}
|
||||
public Client getClientByID(int id) {
|
||||
for (Client client : this.systemClients) {
|
||||
if (client.getID() == id) {
|
||||
return client;
|
||||
}
|
||||
}
|
||||
return new Client("", "");
|
||||
}
|
||||
public void createOrder(int id, Order order) {
|
||||
this.getClientByID(id).addOrder(order);
|
||||
}
|
||||
public ArrayList<Client> getClients() {
|
||||
return this.systemClients;
|
||||
}
|
||||
public Product getProductByID(int id) {
|
||||
for (Product product : this.systemManager.getStorage()) {
|
||||
if (product.getID() == id) {
|
||||
return product;
|
||||
}
|
||||
}
|
||||
return new Product(-1, "", 0, 0);
|
||||
}
|
||||
public StorageManager getManager() {
|
||||
return this.systemManager;
|
||||
}
|
||||
public void showClients() {
|
||||
for (Client client : this.systemClients) {
|
||||
System.out.println(client.toString());
|
||||
}
|
||||
}
|
||||
public void showProducts() {
|
||||
if (this.systemManager.getStorage().isEmpty()) {
|
||||
System.out.println("No products exist");
|
||||
return;
|
||||
}
|
||||
for (Product product : this.systemManager.getStorage()) {
|
||||
System.out.println("ID: " + product.getID() + ", Name: " + product.getName() + ", Price: " + product.getPrice() + ", Amount: " + product.getAmount());
|
||||
}
|
||||
}
|
||||
}
|
36
Technikladen/Product.java
Executable file
36
Technikladen/Product.java
Executable file
@ -0,0 +1,36 @@
|
||||
package tech_store;
|
||||
|
||||
public class Product {
|
||||
private int productID;
|
||||
private String productName;
|
||||
private int productPrice;
|
||||
private int productAmount;
|
||||
public Product(int id, String name, int price, int amt) {
|
||||
this.productID = id;
|
||||
this.productName = name;
|
||||
this.productPrice = price;
|
||||
this.productAmount = amt;
|
||||
}
|
||||
public int getID() {
|
||||
return this.productID;
|
||||
}
|
||||
public String getName() {
|
||||
return this.productName;
|
||||
}
|
||||
public int getPrice() {
|
||||
return this.productPrice;
|
||||
}
|
||||
public int getAmount() {
|
||||
return this.productAmount;
|
||||
}
|
||||
public void reduceAmount(int amt) {
|
||||
if (this.productAmount < amt) {
|
||||
System.out.println("Not enough of product " + this.productID + "(" + this.productName + ") available!");
|
||||
return;
|
||||
}
|
||||
this.productAmount -= amt;
|
||||
}
|
||||
public void increaseAmount(int amt) {
|
||||
this.productAmount += amt;
|
||||
}
|
||||
}
|
14
Technikladen/Receipt.java
Executable file
14
Technikladen/Receipt.java
Executable file
@ -0,0 +1,14 @@
|
||||
package tech_store;
|
||||
|
||||
public class Receipt {
|
||||
private Order receiptOrder;
|
||||
private Client receiptClient;
|
||||
public Receipt(Order order, Client client) {
|
||||
this.receiptOrder = order;
|
||||
this.receiptClient = client;
|
||||
}
|
||||
public void printReceipt() {
|
||||
System.out.println("Client:\n" + this.receiptClient.toString());
|
||||
System.out.println(this.receiptOrder.createReceipt());
|
||||
}
|
||||
}
|
27
Technikladen/StorageManager.java
Executable file
27
Technikladen/StorageManager.java
Executable file
@ -0,0 +1,27 @@
|
||||
package tech_store;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class StorageManager {
|
||||
private ArrayList<Product> storageProducts;
|
||||
public StorageManager(ArrayList<Product> products) {
|
||||
this.storageProducts = products;
|
||||
}
|
||||
public void addProduct(Product product) {
|
||||
this.storageProducts.add(product);
|
||||
}
|
||||
public ArrayList<Product> getStorage() {
|
||||
return this.storageProducts;
|
||||
}
|
||||
public void increaseStorage(int id, int amt) {
|
||||
this.getProductByID(id).increaseAmount(amt);
|
||||
}
|
||||
public Product getProductByID(int id) {
|
||||
for (Product product : this.storageProducts) {
|
||||
if (product.getID() == id) {
|
||||
return product;
|
||||
}
|
||||
}
|
||||
return new Product(-1, "", 0, 0);
|
||||
}
|
||||
}
|
113
Technikladen/TechStore.java
Executable file
113
Technikladen/TechStore.java
Executable file
@ -0,0 +1,113 @@
|
||||
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<Product>());
|
||||
OrderSystem system = new OrderSystem(manager, new ArrayList<Client>());
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user