diff --git a/Cart.java b/Cart.java new file mode 100644 index 0000000..0720e20 --- /dev/null +++ b/Cart.java @@ -0,0 +1,45 @@ +package Shop; +import Shop.Products; +import java.util.ArrayList; + +public class Cart { + private ArrayList cartContents; + + public Cart() { + cartContents = new ArrayList(); + } + + + //Adding stuff to Cart (adding stuff to cart means removing from stock) + public boolean AddCart(Products prod){ + if (prod.getStock() > 0) { // checking if product is in stock + cartContents.add(prod); // adding to cart + prod.setStock(prod.getStock() - 1); // removing from stock + return true; + } + return false; + } + + public int NumberOfArticels (Products prod){ + int nums = 0; + for(Products p: cartContents){ + if(p.equals(prod)){ + nums++; + } + } + return nums; + } + + //removing stuff from cart (means adding back to stock) + public boolean RemoveCart(Products prod){ + if ( NumberOfArticels(prod) > 0) { // checking if product is in stock + if(cartContents.remove(prod)){ // removing from cart + prod.setStock(prod.getStock() + 1); // adding back to stock + return true; + } + } + return false; + } + + +} \ No newline at end of file diff --git a/Products.java b/Products.java index 6c8d166..099c236 100644 --- a/Products.java +++ b/Products.java @@ -22,11 +22,22 @@ import java.util.*; public int getProductID() { return productID; } + public void setProductID(int productID) { + this.productID = productID; + } public String getName() { return Name; } + public void setName(String name) { + this.Name = name; + } + + public void setWeight(double weight) { + this.weight = weight; + } + public double getWeight() { return weight; } @@ -34,13 +45,24 @@ import java.util.*; public double getNetWorth() { return netWorth; } + public void setNetWorth(double netWorth) { + this.netWorth = netWorth; + } public double getTax() { return tax; } + public void setTax(double newTax) { + this.tax = newTax; + } + public int getStock() { - return stock; + return this.stock; + } + //neuer Bestand setzen + public void setStock(int newStock) { + this.stock = newStock; } // Brutto Preis @@ -48,10 +70,7 @@ import java.util.*; return this.netWorth * (1 + this.tax / 100); } - // Reine Steuer - public double getTaxAmount() { - return this.getGrossPrice() - this.netWorth; - } + public String toString() { return "ID:" + this.productID + ", \n" //1. ID