Closes #1, closes #5 ; löschen von überflüssigen Exceptions

main
Laura Kalkbrenner 2026-01-09 01:20:31 +01:00
parent e20ed20406
commit 3343b13e27
3 changed files with 19 additions and 31 deletions

View File

@ -22,18 +22,13 @@ public class OnlineShop {
this.warenkorb = wk;
}
public String [][] Start() throws FileNotFoundException {
LagerList=readFile();
String [][]arr= produktArray(LagerList);
return arr;
}
public String[][] produktArray(ArrayList Lagerlist) throws FileNotFoundException {
public String[][] produktArray() {
String[] Lager = new String[LagerList.size()];
for (int i = 0; i < LagerList.size(); i++){
Lager[i] = LagerList.get(i);
@ -52,8 +47,8 @@ public class OnlineShop {
return produktArray;
}
public String[][] printArray() throws FileNotFoundException {
String [][] arr = produktArray(LagerList);
public String[][] printArray() {
String [][] arr = produktArray();
String[][] arrayForPrint = new String[arr.length][arr[0].length];
for(int i=0;i<arrayForPrint.length;i++){
for(int j=0;j<arrayForPrint[i].length;j++){
@ -86,7 +81,7 @@ public class OnlineShop {
public ArrayList<Produkt> ÜbertrageListe() throws FileNotFoundException {
LagerList=readFile();
String [][]arr= produktArray(LagerList);
String [][]arr= produktArray();
ArrayList<Produkt>ProduktListe=erstelleListe(arr);
return ProduktListe;
@ -110,7 +105,7 @@ public class OnlineShop {
ProduktListe=ÜbertrageListe();
return ProduktListe;
}
public Produkt suchProdukt(String suche) throws FileNotFoundException {
public Produkt suchProdukt(String suche) {
for(Produkt p : ProduktListe){
if(p.name.equalsIgnoreCase(suche))
return p;
@ -127,11 +122,6 @@ public class OnlineShop {
return bestellung;
}
/* public void angepassterBestand() throws FileNotFoundException {
for (int i=0;i<Artikel.size();i++){
ProduktListe.get(i).Bestand-= Artikel.get(i).Menge;
}
}*/
}

View File

@ -12,14 +12,16 @@ class WarenkorbArtikelTest {
Produkt p5= new Produkt(15,"Wein",0.9,5.00,19,9);
Produkt p6 = new Produkt(16,"Kaugummi",0.002,0.98,7,10);
Produkt p7= new Produkt(18,"EuroSchein",0.002,100,5,10);
WarenkorbArtikel w1= new WarenkorbArtikel(p1,2);
WarenkorbArtikel w2= new WarenkorbArtikel(p3,500);
WarenkorbArtikel w3= new WarenkorbArtikel(p4,0);
WarenkorbArtikel war;
WarenkorbArtikel w1= new WarenkorbArtikel(p1,2);
WarenkorbArtikel w2= new WarenkorbArtikel(p3,500);
WarenkorbArtikel w3= new WarenkorbArtikel(p4,0);
WarenkorbArtikel war= new WarenkorbArtikel();
}@Test
@Test
void TestBerechneGPreis(){
// assertEquals(1.66,WarenkorbArtikel.berechneGesamtPreis(w1) );
}
assertEquals(1.66, war.berechneGesamtPreis() );
}
}

View File

@ -1,6 +1,5 @@
package pack;
import org.junit.Before;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -24,12 +23,8 @@ class WarenkorbTest {
@BeforeEach
public void Listeerstellen() throws FileNotFoundException { //(4)
/* for (int i = 0; i < 7; i++) {
String prod = "p" + "i";
produktListe.add(prod);
}*/ produktListe.add(p1);
public void Listeerstellen() { //(4)
produktListe.add(p1);
produktListe.add(p2);
produktListe.add(p3);
produktListe.add(p4);
@ -62,7 +57,7 @@ class WarenkorbTest {
assertEquals(true, warenkorb.ProduktDa(p3.ID,500));
}
@Test
void welchesProdukt() throws FileNotFoundException {
void welchesProdukt() {
assertEquals(p4, warenkorb.welchesProdukt(27));
assertEquals(null, warenkorb.welchesProdukt(101));
}
@ -71,4 +66,5 @@ class WarenkorbTest {
assertEquals(false, warenkorb.aufLager(p4,300));
assertEquals(true, warenkorb.aufLager(p3,200));
}
}