diff --git a/OnlineShop2024/src/de/hs_mannheim/informatik/rhenus/domain/OnlineShop.java b/OnlineShop2024/src/de/hs_mannheim/informatik/rhenus/domain/OnlineShop.java index 2e7b5bd..c6374d6 100644 --- a/OnlineShop2024/src/de/hs_mannheim/informatik/rhenus/domain/OnlineShop.java +++ b/OnlineShop2024/src/de/hs_mannheim/informatik/rhenus/domain/OnlineShop.java @@ -7,6 +7,7 @@ import java.util.Scanner; public class OnlineShop { private ArrayList lager; + private Warenkorb w1 = new Warenkorb(); public OnlineShop() throws FileNotFoundException { lager = new ArrayList<>(); @@ -51,4 +52,21 @@ public class OnlineShop { return trefferliste.toArray(new Produkt[0]); } + + public Warenkorb addItems(Produkt produkt){ + + w1.addItem(produkt); + return w1; + } + + public Warenkorb removeItem(Produkt produkt){ + if(w1.getItems().size() > 0){ + w1.removeItem(produkt); + } + else{ + System.out.println("Warenkorb ist leer."); + } + + return w1; + } } diff --git a/OnlineShop2024/src/de/hs_mannheim/informatik/rhenus/domain/Warenkorb.java b/OnlineShop2024/src/de/hs_mannheim/informatik/rhenus/domain/Warenkorb.java index 83ad3b1..f863fe0 100644 --- a/OnlineShop2024/src/de/hs_mannheim/informatik/rhenus/domain/Warenkorb.java +++ b/OnlineShop2024/src/de/hs_mannheim/informatik/rhenus/domain/Warenkorb.java @@ -1,5 +1,29 @@ package de.hs_mannheim.informatik.rhenus.domain; -public class Warenkorb { +import java.util.ArrayList; +public class Warenkorb { + private ArrayList items; + + public Warenkorb(){ + items = new ArrayList<>(); + } + + public ArrayList addItem(Produkt p){ + items.add(p); + return items; + } + + public ArrayList showWarenkorb(){ + return items; + } + + public ArrayList removeItem(Produkt p){ + items.remove(p); + return items; + } + + public ArrayList getItems(){ + return items; + } }