Commit 7
Fehler ausbesserung implementierung der fehlenden methoden und classen im Cart hinzugefügtmain
parent
ad85a4aeba
commit
4c06b681bf
18
Cart.java
18
Cart.java
|
|
@ -9,7 +9,6 @@ public class Cart {
|
|||
cartContents = new ArrayList<Products>();
|
||||
}
|
||||
|
||||
|
||||
//Adding stuff to Cart (adding stuff to cart means removing from stock)
|
||||
public static boolean AddCart(Products prod, int amount){
|
||||
if (prod.getStock() > 0) { // checking if product is in stock
|
||||
|
|
@ -45,7 +44,7 @@ public class Cart {
|
|||
return cartContents.size();
|
||||
}
|
||||
|
||||
public double GrossAmountProd (){
|
||||
public static double GrossAmountProd(){
|
||||
double gross = 0.0;
|
||||
for(Products prod: cartContents) {
|
||||
gross += prod.getGrossPrice();
|
||||
|
|
@ -53,7 +52,7 @@ public class Cart {
|
|||
return gross;
|
||||
}
|
||||
|
||||
public double ContentsMass() {
|
||||
public static double ContentsMass() {
|
||||
double weights = 0.0;
|
||||
for(Products prod: cartContents) {
|
||||
weights += prod.getWeight();
|
||||
|
|
@ -70,7 +69,7 @@ public class Cart {
|
|||
}
|
||||
|
||||
|
||||
public double deliveryCost () {
|
||||
public static double deliveryCost() {
|
||||
|
||||
double weight = ContentsMass();
|
||||
double delivery = 0;
|
||||
|
|
@ -97,7 +96,7 @@ public class Cart {
|
|||
}
|
||||
|
||||
|
||||
public double taxDelivery(){
|
||||
public static double taxDelivery(){
|
||||
double delivery = deliveryCost ();
|
||||
|
||||
double tax7perc = 0; // grosstax is 7% which means: 1/3rd of 19,95
|
||||
|
|
@ -141,4 +140,13 @@ public class Cart {
|
|||
}
|
||||
|
||||
|
||||
public void clear() {
|
||||
for (int i = 0; !cartContents.isEmpty(); i++) {
|
||||
cartContents.remove(1);
|
||||
}
|
||||
}
|
||||
|
||||
public void printCart() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -6,44 +6,51 @@ import java.io.FileNotFoundException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Scanner;
|
||||
|
||||
import static Shop.Shop.cart;
|
||||
|
||||
public class OnlineShop {
|
||||
ArrayList<Products> warehouse;
|
||||
|
||||
public Object OnlineShop() throws FileNotFoundException { //readFile-Methode
|
||||
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()) { //Solange da noch Zeilen im Dokument sind...
|
||||
String Line = scan.nextLine().trim();
|
||||
while (scan.hasNextLine()) {
|
||||
String line = scan.nextLine().trim();
|
||||
String[] Parts = line.split(",");
|
||||
|
||||
while (scan.hasNextLine()) {
|
||||
String line = scan.nextLine().trim();
|
||||
String[] Parts = line.split(",");
|
||||
|
||||
// ANNAHME: Die CSV-Zeile hat 6 Spalten (ID, Name, Gewicht, NetWorth, Tax, Stock)
|
||||
if (Parts.length == 6) {
|
||||
try {
|
||||
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());
|
||||
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);
|
||||
} catch (NumberFormatException e) {
|
||||
System.err.println("Fehler beim Parsen numerischer Daten in Zeile: " + Line);
|
||||
}
|
||||
}
|
||||
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();
|
||||
|
||||
}
|
||||
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;
|
||||
|
|
@ -74,13 +81,13 @@ public class OnlineShop {
|
|||
return wholeAmount;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
|
||||
|
||||
Products getProductById(int ProductID) {
|
||||
int i = 0;
|
||||
while (i < warehouse.size()) {
|
||||
if (warehouse.get(i).getProductID() == id) {
|
||||
if (ProductID == warehouse.get(i).getProductID()) {
|
||||
return warehouse.get(i);
|
||||
}
|
||||
i++;
|
||||
|
|
@ -98,12 +105,12 @@ public class OnlineShop {
|
|||
}
|
||||
}
|
||||
|
||||
OrderCustomer createOrder(String customerName, String Adress, Cart cart) {
|
||||
double net = Cart.getnetWorth();
|
||||
double tax = Cart.getTaxDelivery();
|
||||
double gross = Cart.getGrossTotal();
|
||||
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(name, Address, cart, net, tax, gross);
|
||||
Order order = new Order(customerName, Adress, cart, net, tax, gross);
|
||||
cart.clear();
|
||||
return order;
|
||||
}
|
||||
|
|
@ -117,11 +124,10 @@ public class OnlineShop {
|
|||
private double tax;
|
||||
private double gross;
|
||||
|
||||
public Order(String customerName, String address, Cart cart,
|
||||
double net, double tax, 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.copy();
|
||||
this.cart = cart;
|
||||
this.net = net;
|
||||
this.tax = tax;
|
||||
this.gross = gross;
|
||||
|
|
@ -138,4 +144,4 @@ public class OnlineShop {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import java.util.*;
|
|||
private double grossWorth;
|
||||
private String Name;
|
||||
private double weight;
|
||||
private double netWorth;
|
||||
private static double netWorth;
|
||||
private double tax;
|
||||
private int productID;
|
||||
private int stock;
|
||||
|
|
@ -19,7 +19,7 @@ import java.util.*;
|
|||
this.stock = stock;
|
||||
this.productID = productID;
|
||||
}
|
||||
public String getProductID() {
|
||||
public int getProductID() {
|
||||
return productID;
|
||||
}
|
||||
public void setProductID(int productID) {
|
||||
|
|
@ -42,7 +42,7 @@ import java.util.*;
|
|||
return weight;
|
||||
}
|
||||
|
||||
public double getNetWorth() {
|
||||
public static double getNetWorth() {
|
||||
return netWorth;
|
||||
}
|
||||
public void setNetWorth(double netWorth) {
|
||||
|
|
@ -57,8 +57,8 @@ import java.util.*;
|
|||
this.tax = newTax;
|
||||
}
|
||||
|
||||
public static int getStock() {
|
||||
return this.stock;
|
||||
public int getStock() {
|
||||
return this.stock;
|
||||
}
|
||||
//neuer Bestand setzen
|
||||
public void setStock(int newStock) {
|
||||
|
|
|
|||
12
Shop.java
12
Shop.java
|
|
@ -40,7 +40,10 @@ public class Shop {
|
|||
} else if (eingabe.equals("produktsuche") || eingabe.equals("suche")) {
|
||||
Search();
|
||||
} else if (eingabe.equals("warenkorb")) {
|
||||
Cart();
|
||||
System.out.println(" ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄");
|
||||
System.out.println(" Auf Wiedersehen! ");
|
||||
System.out.println("____________________________");
|
||||
|
||||
} else if (eingabe.equals("beenden")) {
|
||||
System.out.println(" ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄");
|
||||
System.out.println(" Auf Wiedersehen! ");
|
||||
|
|
@ -56,11 +59,11 @@ public class Shop {
|
|||
|
||||
public static void Sale() {
|
||||
System.out.println("\n\n\n Produkte: \n");
|
||||
Products[] produkte = shop.ProductList();
|
||||
String[] products = OnlineShop.ProductList();
|
||||
|
||||
for (int i = 0; i < produkte.length; i++) {
|
||||
for (int i = 0; i < products.length;i++) {
|
||||
Products prod = shop.warehouse.get(i);
|
||||
System.out.printf(prod.getProductID(), prod.getName(), prod.getGrossPrice());
|
||||
System.out.printf(prod.getProductID() +" " + prod.getName()+""+ prod.getGrossPrice());
|
||||
}
|
||||
|
||||
System.out.println("\nWählen Sie ein Produkt anhand der Artikelnummer für Ihren Warenkorb aus \noder geben Sie 'Hauptmenü' an, wenn Sie zurück wollen: ");
|
||||
|
|
@ -132,7 +135,6 @@ public class Shop {
|
|||
mainMenu();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue