Commit 3
Fertigstellung der Produkte, Implementierung des Warenkorbs, hinzufügen und entfernen von Artikeln zum/ aus dem Warenkorbmain
parent
928dbbb5bd
commit
70e4b9e3fb
|
|
@ -0,0 +1,45 @@
|
|||
package Shop;
|
||||
import Shop.Products;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Cart {
|
||||
private ArrayList<Products> cartContents;
|
||||
|
||||
public Cart() {
|
||||
cartContents = new ArrayList<Products>();
|
||||
}
|
||||
|
||||
|
||||
//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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue