Implementierung der csv Datei und der Bestellungen
main
Fatima Zehra Ulu 2025-12-15 04:48:46 +01:00
parent d77718aa96
commit b3269c7535
1 changed files with 62 additions and 37 deletions

View File

@ -1,54 +1,79 @@
package Shop; 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<Products> 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{ while (scan.hasNextLine()) { //Solange da noch Zeilen im Dokument sind...
private String Name; String Line = scan.nextLine().trim();
private double weight;
private double netWorth;
private double tax;
private int stock;
// Constructor for the Products class if (Line.length() == 5) {
public Products(String Name, double weight, double netWorth, double tax, int stock) { String[] Parts = Line.split(",");
this.Name = Name;
this.weight = weight; int productID = Integer.parseInt(Parts[0]);
this.netWorth = netWorth; String Name = Parts[1];
this.tax = tax; double weight = Double.parseDouble(Parts[2]);
this.stock = stock; 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; return Name;
} }
public double getWeight(){
return weight; public String getAdresse() {
} return Adress;
public double getNetWorth(){
return netWorth;
}
public double getTax(){
return tax;
}
public int getStock(){
return stock;
} }
// Brutto Preis public Cart getCart() {
public double getGrossPrice(){ return cart;
return this.netWorth *(1+this.tax/100);
} }
// Reine Steuer public double wholeAmount() {
public double getTaxAmount(){ return wholeAmount;
return this.getGrossPrice()-this.netWorth;
} }
} }
}
}