+ JUnit
+ Tests für Warenkorb: Hinzufügen, Menge ändern, Entfernen und Leerzustandmain
parent
f11dcbf4ef
commit
e36320e6bf
|
|
@ -13,8 +13,7 @@ public class OnlineShop {
|
||||||
lager = new ArrayList<Produkt>();
|
lager = new ArrayList<Produkt>();
|
||||||
|
|
||||||
Scanner sc = new Scanner(new File("././resources/produkte.csv"));
|
Scanner sc = new Scanner(new File("././resources/produkte.csv"));
|
||||||
|
sc.nextLine();
|
||||||
if (sc.hasNextLine()) sc.nextLine();
|
|
||||||
|
|
||||||
while(sc.hasNextLine() ) {
|
while(sc.hasNextLine() ) {
|
||||||
String zeile = sc.nextLine();
|
String zeile = sc.nextLine();
|
||||||
|
|
@ -28,7 +27,6 @@ public class OnlineShop {
|
||||||
int bestand = Integer.parseInt(teile[5]);
|
int bestand = Integer.parseInt(teile[5]);
|
||||||
|
|
||||||
Produkt p = new Produkt(id, name, gewicht, preis, mwst, bestand);
|
Produkt p = new Produkt(id, name, gewicht, preis, mwst, bestand);
|
||||||
|
|
||||||
lager.add(p);
|
lager.add(p);
|
||||||
}
|
}
|
||||||
sc.close();
|
sc.close();
|
||||||
|
|
|
||||||
|
|
@ -2,20 +2,15 @@ package backend;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class Warenkorb {
|
public class Warenkorb {
|
||||||
private ArrayList<Produkt> inhalt;
|
|
||||||
private ArrayList<WarenkorbPosition> positionen;
|
private ArrayList<WarenkorbPosition> positionen;
|
||||||
|
|
||||||
|
|
||||||
public Warenkorb() {
|
public Warenkorb() {
|
||||||
inhalt = new ArrayList<Produkt>();
|
|
||||||
positionen = new ArrayList<>();
|
positionen = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void produktHinzufügen(Produkt p, int menge) {
|
public void produktHinzufügen(Produkt p, int menge) {
|
||||||
for (int i = 0; i < menge; i++) {
|
|
||||||
inhalt.add(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean gefunden = false;
|
boolean gefunden = false;
|
||||||
for (WarenkorbPosition wp : positionen) {
|
for (WarenkorbPosition wp : positionen) {
|
||||||
|
|
@ -37,7 +32,7 @@ public class Warenkorb {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void pEntfernen(Produkt p) {
|
public void entfernen(Produkt p) {
|
||||||
ArrayList<WarenkorbPosition> neu = new ArrayList<>();
|
ArrayList<WarenkorbPosition> neu = new ArrayList<>();
|
||||||
|
|
||||||
for (WarenkorbPosition wp : positionen) {
|
for (WarenkorbPosition wp : positionen) {
|
||||||
|
|
@ -51,7 +46,7 @@ public class Warenkorb {
|
||||||
|
|
||||||
public boolean mengeAendern(Produkt p, int neu) {
|
public boolean mengeAendern(Produkt p, int neu) {
|
||||||
if (neu == 0) {
|
if (neu == 0) {
|
||||||
this.pEntfernen(p);
|
this.entfernen(p);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -246,7 +246,7 @@ public class shopTUI {
|
||||||
|
|
||||||
if (neu == 0) {
|
if (neu == 0) {
|
||||||
shop.erhöhen(p, alt);
|
shop.erhöhen(p, alt);
|
||||||
warenkorb.pEntfernen(p);
|
warenkorb.entfernen(p);
|
||||||
System.out.println("Die Position wurde gelöscht! ✧。٩(ˊᗜˋ)و✧*。");
|
System.out.println("Die Position wurde gelöscht! ✧。٩(ˊᗜˋ)و✧*。");
|
||||||
} else if (x > 0 && p.getBestand() < x) {
|
} else if (x > 0 && p.getBestand() < x) {
|
||||||
System.out.println("Leider reicht unser Bestand nicht aus (˃̣̣̥ᯅ˂̣̣̥)");
|
System.out.println("Leider reicht unser Bestand nicht aus (˃̣̣̥ᯅ˂̣̣̥)");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue