#Feat - addProdukt, removeProduct implementiert
parent
9a45ec9264
commit
ba178e05fd
|
|
@ -13,4 +13,9 @@ Code Gym - Get and Set
|
||||||
https://codegym.cc/de/groups/posts/getter-und-setter-in-java
|
https://codegym.cc/de/groups/posts/getter-und-setter-in-java
|
||||||
|
|
||||||
Bro Code - How to read a File
|
Bro Code - How to read a File
|
||||||
https://www.youtube.com/watch?v=eHjbvgw4hsI
|
https://www.youtube.com/watch?v=eHjbvgw4hsI
|
||||||
|
|
||||||
|
|
||||||
|
Baeldung - ConcurrentModificationException
|
||||||
|
https://www.baeldung.com/java-concurrentmodificationexception
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,42 @@
|
||||||
package shop.backend;
|
package shop.backend;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Cart {
|
public class Cart {
|
||||||
|
|
||||||
|
private List<CartPosition> positions;
|
||||||
|
|
||||||
|
public Cart(){
|
||||||
|
this.positions = new ArrayList<>();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addProduct(Product prod, int quantity){
|
||||||
|
//Ich überprüfe damit ob es das Produkt gibt
|
||||||
|
for(CartPosition pos : positions){
|
||||||
|
//Ist es das Produkt? Hat es dieselbe ID? ---> Ja ---> Quantity erhöhen---->break
|
||||||
|
if(pos.getProduct().getProdID() == prod.getProdID()){
|
||||||
|
pos.setQuantity(pos.getQuantity() + quantity); //Damit erhöhe ich quantity
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
positions.add(new CartPosition(prod, quantity));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void removeProduct(int productID){
|
||||||
|
CartPosition gettinYETTED = null;
|
||||||
|
for(CartPosition pos : positions){
|
||||||
|
|
||||||
|
if(pos.getProduct().getProdID() == productID){
|
||||||
|
gettinYETTED = pos;
|
||||||
|
break; // Gefunden, abbrechnen
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//
|
||||||
|
if(gettinYETTED != null){
|
||||||
|
positions.remove(gettinYETTED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue