148 lines
4.7 KiB
Java
148 lines
4.7 KiB
Java
package Shop;
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.FileNotFoundException;
|
|
import java.util.ArrayList;
|
|
import java.util.Scanner;
|
|
|
|
public class OnlineShop {
|
|
ArrayList<Products> warehouse;
|
|
|
|
public Object OnlineShop() throws FileNotFoundException {
|
|
warehouse = new ArrayList<>();
|
|
|
|
//Einlesen
|
|
Scanner scan = new Scanner(new File("resources/produkte.csv")); //Scanner erstellen
|
|
scan.nextLine();
|
|
|
|
while (scan.hasNextLine()) {
|
|
String line = scan.nextLine().trim();
|
|
String[] Parts = line.split(",");
|
|
|
|
|
|
if (Parts.length == 6) {
|
|
int productID = Integer.parseInt(Parts[0].trim()); // ID ist jetzt da
|
|
String Name = Parts[1].trim();
|
|
double weight = Double.parseDouble(Parts[2].trim());
|
|
double netWorth = Double.parseDouble(Parts[3].trim());
|
|
double tax = Double.parseDouble(Parts[4].trim()); // z.B. 7.0 oder 19.0
|
|
int stock = Integer.parseInt(Parts[5].trim());
|
|
|
|
Products prod = new Products(Name, weight, netWorth, tax, stock, productID);
|
|
warehouse.add(prod);
|
|
} else {
|
|
System.err.println("Fehler beim Parsen numerischer Daten in Zeile: " + line);
|
|
}
|
|
|
|
}
|
|
scan.close();
|
|
|
|
return null;
|
|
}
|
|
static String[] ProductList(){
|
|
ArrayList<Products> warehouse;
|
|
warehouse = new ArrayList<>();
|
|
String[] productList = new String[warehouse.size()];
|
|
for (int i = 0; i < warehouse.size(); i++) {
|
|
productList[i] = warehouse.get(i).toString();
|
|
}
|
|
|
|
return productList;
|
|
}
|
|
|
|
|
|
class OrderCustomer {
|
|
private String CustomerName;
|
|
private String Adress;
|
|
private Cart cart;
|
|
private double wholeAmount;
|
|
|
|
public OrderCustomer(String Name, String Adress, Cart cart, double wholeAmount) {
|
|
this.CustomerName = Name;
|
|
this.Adress = Adress;
|
|
this.cart = cart;
|
|
this.wholeAmount = wholeAmount;
|
|
}
|
|
|
|
public String getName() {
|
|
return CustomerName;
|
|
}
|
|
|
|
public String getAdresse() {
|
|
return Adress;
|
|
}
|
|
|
|
public Cart getCart() {
|
|
return cart;
|
|
}
|
|
|
|
public double wholeAmount() {
|
|
return wholeAmount;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Products getProductById(int ProductID) {
|
|
int i = 0;
|
|
while (i < warehouse.size()) {
|
|
if (ProductID == warehouse.get(i).getProductID()) {
|
|
return warehouse.get(i);
|
|
}
|
|
i++;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public void showProducts() {
|
|
int i = 0;
|
|
while (i < warehouse.size()) {
|
|
Products p = warehouse.get(i);
|
|
System.out.println(p.getProductID() + " | " + p.getName() + " | " +
|
|
String.format("%.2f €", p.getGrossPrice()) + " | Bestand: " + p.getStock());
|
|
i++;
|
|
}
|
|
}
|
|
|
|
OnlineShop.Order createOrder(String customerName, String Adress, Cart cart) {
|
|
double net = Products.getNetWorth();
|
|
double tax = Cart.taxDelivery();
|
|
double gross = Cart.GrossAmountProd();
|
|
|
|
Order order = new Order(customerName, Adress, cart, net, tax, gross);
|
|
cart.clear();
|
|
return order;
|
|
}
|
|
|
|
|
|
public static class Order {
|
|
private String customerName;
|
|
private String address;
|
|
private Cart cart;
|
|
private double net;
|
|
private double tax;
|
|
private double gross;
|
|
|
|
public Order(String customerName, String address, Cart cart, double net, double tax, double gross) {
|
|
this.customerName = customerName;
|
|
this.address = address;
|
|
this.cart = cart;
|
|
this.net = net;
|
|
this.tax = tax;
|
|
this.gross = gross;
|
|
}
|
|
|
|
public void printConfirmation() {
|
|
System.out.println("===== BESTELLBESTÄTIGUNG =====");
|
|
System.out.println("Name: " + customerName);
|
|
System.out.println("Adresse: " + address);
|
|
cart.printCart();
|
|
System.out.println("Netto: " + net + " €");
|
|
System.out.println("MwSt: " + tax + " €");
|
|
System.out.println("Brutto: " + gross + " €");
|
|
}
|
|
}
|
|
}
|
|
|