From 3e1ef782898abf5e9abbf7d82ee65b4920f47ef9 Mon Sep 17 00:00:00 2001 From: 3007492 <3007492@hs-mannheim.de> Date: Thu, 17 Oct 2024 17:02:19 +0200 Subject: [PATCH] =?UTF-8?q?Warenkorb=20funktion=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../informatik/rhenus/domain/OnlineShop.java | 18 +++++++++++++ .../informatik/rhenus/domain/Warenkorb.java | 26 ++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) 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; + } }