From b3269c753587221a57056fc6dbb100a1b0869ea8 Mon Sep 17 00:00:00 2001 From: Fatima Zehra Ulu <3026753@stud.hs-mannheim.de> Date: Mon, 15 Dec 2025 04:48:46 +0100 Subject: [PATCH] Commit 5 Implementierung der csv Datei und der Bestellungen --- OnlineShop.java | 99 +++++++++++++++++++++++++++++++------------------ 1 file changed, 62 insertions(+), 37 deletions(-) diff --git a/OnlineShop.java b/OnlineShop.java index a36bdbf..b40d7fb 100644 --- a/OnlineShop.java +++ b/OnlineShop.java @@ -1,54 +1,79 @@ package Shop; -public class OnlineShop{ +import Shop.Cart; +import Shop.Products; +import java.io.File; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.Scanner; -public static void main (String [] args){ +public class OnlineShop { + private ArrayList warehouse; + public OnlineShop throws FileNotFoundException { //readFile-Methode + warehouse = new ArrayList<>(); -} + //Einlesen + Scanner scan = new Scanner(new File("resources/produkte.csv")); //Scanner erstellen + scan.nextLine(); - public class Products{ - private String Name; - private double weight; - private double netWorth; - private double tax; - private int stock; + while (scan.hasNextLine()) { //Solange da noch Zeilen im Dokument sind... + String Line = scan.nextLine().trim(); - // Constructor for the Products class - public Products(String Name, double weight, double netWorth, double tax, int stock) { - this.Name = Name; - this.weight = weight; - this.netWorth = netWorth; - this.tax = tax; - this.stock = stock; + if (Line.length() == 5) { + String[] Parts = Line.split(","); + + int productID = Integer.parseInt(Parts[0]); + String Name = Parts[1]; + double weight = Double.parseDouble(Parts[2]); + double netWorth = Double.parseDouble(Parts[3]); + double tax = Double.parseDouble(Parts[4]); + int stock = Integer.parseInt(Parts[5]); + + Products prod = new Products(Name, weight, netWorth, tax, stock, productID); + warehouse.add(prod); + }} + + scan.close(); + } + public String[] ProductList() { + String[] productList = new String [warehouse.size()]; + for (int i = 0; i < warehouse.size(); i++) { + productList[i] = warehouse.get(i).toString(); + } + + return productList; } - public String getName(){ + public class Order { + private String Name; + private String Adress; + private Cart cart; + private double wholeAmount; + + public Order(String Name, String Adress, Cart cart, double wholeAmount) { + this.Name = Name; + this.Adress = Adress; + this.cart = cart; + this.wholeAmount = wholeAmount; + } + + public String getName() { return Name; } - public double getWeight(){ - return weight; - } - public double getNetWorth(){ - return netWorth; - } - public double getTax(){ - return tax; - } - public int getStock(){ - return stock; + + public String getAdresse() { + return Adress; } - // Brutto Preis - public double getGrossPrice(){ - return this.netWorth *(1+this.tax/100); + public Cart getCart() { + return cart; } - // Reine Steuer - public double getTaxAmount(){ - return this.getGrossPrice()-this.netWorth; + public double wholeAmount() { + return wholeAmount; } - - } -} + + +} \ No newline at end of file