Implementierung einer Such-Funktion
parent
8be9721223
commit
9e7b077820
|
|
@ -10,6 +10,7 @@ import java.util.Scanner;
|
||||||
public class OnlineShop {
|
public class OnlineShop {
|
||||||
private static ArrayList<String> LagerList;
|
private static ArrayList<String> LagerList;
|
||||||
|
|
||||||
|
|
||||||
public String [][] Start() throws FileNotFoundException {
|
public String [][] Start() throws FileNotFoundException {
|
||||||
LagerList=readFile();
|
LagerList=readFile();
|
||||||
String [][]arr= produktArray(LagerList);
|
String [][]arr= produktArray(LagerList);
|
||||||
|
|
@ -18,6 +19,8 @@ public class OnlineShop {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public String[][] produktArray(ArrayList Lagerlist) throws FileNotFoundException {
|
public String[][] produktArray(ArrayList Lagerlist) throws FileNotFoundException {
|
||||||
String[] Lager = new String[LagerList.size()];
|
String[] Lager = new String[LagerList.size()];
|
||||||
for (int i = 0; i < LagerList.size(); i++){
|
for (int i = 0; i < LagerList.size(); i++){
|
||||||
|
|
@ -54,6 +57,16 @@ public class OnlineShop {
|
||||||
return ProduktListe;
|
return ProduktListe;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArrayList<Produkt> ÜbertrageListe() throws FileNotFoundException {
|
||||||
|
LagerList=readFile();
|
||||||
|
String [][]arr= produktArray(LagerList);
|
||||||
|
String[][] produktArray = Start();
|
||||||
|
ArrayList<Produkt>ProduktListe=erstelleListe(arr);
|
||||||
|
|
||||||
|
return ProduktListe;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static ArrayList<String> readFile() throws FileNotFoundException {
|
public static ArrayList<String> readFile() throws FileNotFoundException {
|
||||||
|
|
||||||
Scanner sc = new Scanner(new File("Shop/resources/produkte.csv")); //Vom Sudoku übernommen
|
Scanner sc = new Scanner(new File("Shop/resources/produkte.csv")); //Vom Sudoku übernommen
|
||||||
|
|
@ -66,5 +79,25 @@ public class OnlineShop {
|
||||||
|
|
||||||
return LagerList;
|
return LagerList;
|
||||||
}
|
}
|
||||||
|
public boolean[] aufLager() throws FileNotFoundException { //TODO Prüfen ob ich die Methode überhaupt brauche
|
||||||
|
ArrayList<Produkt> ProduktListe= ÜbertrageListe();
|
||||||
|
boolean[] aufLager= new boolean[ProduktListe.size()];
|
||||||
|
for(int i=0;i<ProduktListe.size();i++) {
|
||||||
|
if(ProduktListe.get(i).Bestand >0)
|
||||||
|
aufLager[i]=true;
|
||||||
|
else
|
||||||
|
aufLager[i]=false;
|
||||||
|
}
|
||||||
|
return aufLager;
|
||||||
|
}
|
||||||
|
public Produkt suchProdukt(String suche) throws FileNotFoundException {
|
||||||
|
ArrayList<Produkt>ProduktListe= ÜbertrageListe();
|
||||||
|
for(Produkt p : ProduktListe){
|
||||||
|
if(p.name.equalsIgnoreCase(suche))
|
||||||
|
return p;
|
||||||
|
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ public class Produkt {
|
||||||
return preis-berechneMwst();
|
return preis-berechneMwst();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
/* public boolean equals(Object o) {
|
||||||
if (!(o instanceof Produkt))
|
if (!(o instanceof Produkt))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
@ -38,5 +38,6 @@ public class Produkt {
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,5 +24,11 @@ public class Warenkorb {
|
||||||
|
|
||||||
return preis;
|
return preis;
|
||||||
}
|
}
|
||||||
|
public double berechneGesamtGewicht() {
|
||||||
|
double gewicht = 0;
|
||||||
|
for (Produkt p : inhalt)
|
||||||
|
gewicht+= p.Gewicht*1000; //für kg für den Versand
|
||||||
|
return gewicht;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,18 @@
|
||||||
package pack;
|
package pack;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class ShopTUI {
|
public class ShopTUI {
|
||||||
private static OnlineShop shop;
|
private static OnlineShop shop;
|
||||||
|
static Scanner sc = new Scanner(System.in);
|
||||||
|
|
||||||
public static void main(String[] args) throws FileNotFoundException {
|
public static void main(String[] args) throws FileNotFoundException {
|
||||||
System.out.println("Willkommen zum DanDan-Shop!");
|
System.out.println("Willkommen zum DanDan-Shop!");
|
||||||
shop= new OnlineShop();
|
shop= new OnlineShop();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
boolean cont = true;
|
boolean cont = true;
|
||||||
|
|
||||||
while (cont) {
|
while (cont) {
|
||||||
|
|
@ -33,7 +31,6 @@ public class ShopTUI {
|
||||||
IO.println("3.Mein Warenkorb");
|
IO.println("3.Mein Warenkorb");
|
||||||
IO.println("4. Bestellungen");
|
IO.println("4. Bestellungen");
|
||||||
IO.println("5. Exit ");
|
IO.println("5. Exit ");
|
||||||
Scanner sc = new Scanner(System.in);
|
|
||||||
IO.print(">>");
|
IO.print(">>");
|
||||||
String eingabe = sc.nextLine();
|
String eingabe = sc.nextLine();
|
||||||
switch (eingabe) {
|
switch (eingabe) {
|
||||||
|
|
@ -41,7 +38,7 @@ public class ShopTUI {
|
||||||
produktangebot();
|
produktangebot();
|
||||||
break;
|
break;
|
||||||
case "2": case "suche": case "Suche": case"produktsuche":
|
case "2": case "suche": case "Suche": case"produktsuche":
|
||||||
//Todo suchfunktiom
|
produktsuche();
|
||||||
break;
|
break;
|
||||||
case "3": case "warenkorb": case"Warenkorb":
|
case "3": case "warenkorb": case"Warenkorb":
|
||||||
//Todo warenkorb
|
//Todo warenkorb
|
||||||
|
|
@ -61,7 +58,6 @@ public class ShopTUI {
|
||||||
|
|
||||||
public static void produktangebot() throws FileNotFoundException {
|
public static void produktangebot() throws FileNotFoundException {
|
||||||
System.out.println("Unser Produktangebot:");
|
System.out.println("Unser Produktangebot:");
|
||||||
|
|
||||||
String[][] produkt = shop.Start();
|
String[][] produkt = shop.Start();
|
||||||
|
|
||||||
IO.println();
|
IO.println();
|
||||||
|
|
@ -81,6 +77,43 @@ public class ShopTUI {
|
||||||
IO.println();
|
IO.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} public static void produktsuche() throws FileNotFoundException {
|
||||||
|
IO.print("Ich suche: ");
|
||||||
|
String suche = sc.nextLine();
|
||||||
|
int count=0;
|
||||||
|
Produkt vlt=null;
|
||||||
|
boolean[] aufLager= shop.aufLager();
|
||||||
|
ArrayList<Produkt> ProduktListe= shop.ÜbertrageListe();
|
||||||
|
IO.println();
|
||||||
|
Produkt gefunden= shop.suchProdukt(suche);
|
||||||
|
if(gefunden==null) {
|
||||||
|
/* for(int i=0;i<ProduktListe.size();i++) {
|
||||||
|
for (int j = 0; j < 5&& j<ProduktListe.get(i).name.length(); j++) {
|
||||||
|
if (suche.charAt(j) == ProduktListe.get(i).name.charAt(j)){
|
||||||
|
count++;
|
||||||
|
if(count==5){
|
||||||
|
vlt=ProduktListe.get(i);
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} count=0;
|
||||||
|
}
|
||||||
|
if(count==5) {
|
||||||
|
IO.println("Meinten Sie vielleicht "+ vlt.name + " " +vlt.preis+ "€ ?");
|
||||||
|
IO.println("Unser Bestand beträgt"+ vlt.Bestand);
|
||||||
|
}*/
|
||||||
|
IO.println("Das gesuchte Produkt wurde leider nicht gefunden");
|
||||||
|
} else {
|
||||||
|
IO.println("Hier ist das Produkt: " + gefunden.name + " " + gefunden.preis + " €");
|
||||||
|
if(gefunden.Bestand ==0){
|
||||||
|
IO.println("Das Produkt ist aber leider zur Zeit nicht verfügbar");
|
||||||
|
//Todo hier trimen oder splite damit der user nicht sowas wie 7l hinzufügen muss
|
||||||
|
}else
|
||||||
|
IO.println("Wollen sie das Produkt zum Warenkorb hinzufügen?");
|
||||||
|
//Todo hinzufügfen ermöglichen
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue