Close #3 ; close #4 ;

-> Businesslogik aus der TUI entfernt und in die Onlineshop Klasse gemacht. Packages umbenannt
main
Laura Kalkbrenner 2026-01-09 03:37:05 +01:00
parent 07314ec2c7
commit 000eeaa667
10 changed files with 38 additions and 32 deletions

View File

@ -1,4 +1,4 @@
package pack; package Shop.backend;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -1,4 +1,4 @@
package pack; package Shop.backend;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -87,6 +87,22 @@ public class OnlineShop {
return ProduktListe; return ProduktListe;
} }
public Produkt MöglicheSuche(String suche){
Produkt vlt=null;
int count=0;
for(int i=0;i<ProduktListe.size();i++) {
for (int j = 0; j <4&& j<ProduktListe.get(i).name.length(); j++) {
if (suche.charAt(j) == (ProduktListe.get(i).name).charAt(j)){ //Todo gucken warum Ignore.Case nicht klappt
count++;
if(count==3){
vlt=ProduktListe.get(i);
}
}else {
continue;
}
} count=0;
} return vlt;
}
public static ArrayList<String> readFile() throws FileNotFoundException { public static ArrayList<String> readFile() throws FileNotFoundException {

View File

@ -1,12 +1,12 @@
package pack; package Shop.backend;
public class Produkt { public class Produkt {
String name; public String name;
double preis; public double preis;
double mwst; public double mwst;
int ID; int ID;
double Gewicht; double Gewicht;
int Bestand; public int Bestand;
double bruttopreis; double bruttopreis;
double mwstSatz; double mwstSatz;

View File

@ -1,4 +1,4 @@
package pack; package Shop.backend;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;

View File

@ -1,4 +1,4 @@
package pack; package Shop.backend;
public class WarenkorbArtikel { public class WarenkorbArtikel {
Produkt produkt; Produkt produkt;

View File

@ -1,8 +1,14 @@
package pack; package Shop.TUI;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Scanner; import java.util.Scanner;
import Shop.backend.Warenkorb;
import Shop.backend.OnlineShop;
import Shop.backend.Bestellung;
import Shop.backend.Produkt;
import Shop.backend.WarenkorbArtikel;
@ -86,25 +92,13 @@ public class ShopTUI {
} public static void produktsuche() throws FileNotFoundException { } public static void produktsuche() throws FileNotFoundException {
IO.print("Ich suche: "); IO.print("Ich suche: ");
String suche = sc.nextLine(); String suche = sc.nextLine();
int count=0;
Produkt vlt=null;
// boolean[] aufLager= shop.aufLager(); // boolean[] aufLager= shop.aufLager();
ArrayList<Produkt> ProduktListe= shop.getProduktListe(); ArrayList<Produkt> ProduktListe= shop.getProduktListe();
IO.println(); IO.println();
Produkt gefunden= shop.suchProdukt(suche); Produkt gefunden= shop.suchProdukt(suche);
if(gefunden==null) { if(gefunden==null) {
for(int i=0;i<ProduktListe.size();i++) { Produkt vlt= shop.MöglicheSuche(suche);
for (int j = 0; j < 5&& j<ProduktListe.get(i).name.length(); j++) {
if (suche.charAt(j) == (ProduktListe.get(i).name).charAt(j)){ //Todo gucken warum Ignore.Case nicht klappt
count++;
if(count==4){
vlt=ProduktListe.get(i);
}
}else {
continue;
}
} count=0;
}
if(vlt.name.length()>4) { if(vlt.name.length()>4) {
IO.println("Meinten Sie vielleicht "+ vlt.name + " " +vlt.preis+ "€ ?"); IO.println("Meinten Sie vielleicht "+ vlt.name + " " +vlt.preis+ "€ ?");
IO.println("Unser Bestand beträgt "+ vlt.Bestand);//TODO hinzufügen ermöglichen IO.println("Unser Bestand beträgt "+ vlt.Bestand);//TODO hinzufügen ermöglichen

View File

@ -1,9 +1,7 @@
package pack; package Shop.backend;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class OnlineShopTest { class OnlineShopTest {
@Test @Test

View File

@ -1,9 +1,7 @@
package pack; package Shop.backend;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.io.FileNotFoundException;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
class ProduktTest { class ProduktTest {

View File

@ -1,4 +1,4 @@
package pack; package Shop.backend;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;

View File

@ -1,4 +1,4 @@
package pack; package Shop.backend;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;