Warenkorb funktion hinzugefügt

master
3007492 2024-10-17 17:02:19 +02:00
parent 0f03fba94d
commit 3e1ef78289
2 changed files with 43 additions and 1 deletions

View File

@ -7,6 +7,7 @@ import java.util.Scanner;
public class OnlineShop { public class OnlineShop {
private ArrayList<Produkt> lager; private ArrayList<Produkt> lager;
private Warenkorb w1 = new Warenkorb();
public OnlineShop() throws FileNotFoundException { public OnlineShop() throws FileNotFoundException {
lager = new ArrayList<>(); lager = new ArrayList<>();
@ -51,4 +52,21 @@ public class OnlineShop {
return trefferliste.toArray(new Produkt[0]); 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;
}
} }

View File

@ -1,5 +1,29 @@
package de.hs_mannheim.informatik.rhenus.domain; package de.hs_mannheim.informatik.rhenus.domain;
public class Warenkorb { import java.util.ArrayList;
public class Warenkorb {
private ArrayList<Produkt> items;
public Warenkorb(){
items = new ArrayList<>();
}
public ArrayList<Produkt> addItem(Produkt p){
items.add(p);
return items;
}
public ArrayList<Produkt> showWarenkorb(){
return items;
}
public ArrayList<Produkt> removeItem(Produkt p){
items.remove(p);
return items;
}
public ArrayList<Produkt> getItems(){
return items;
}
} }