Methode zum hinzufügen von Artikeln in den Warenkorb implementiert.
parent
5709d78f5b
commit
68002788c5
|
|
@ -32,7 +32,7 @@ public class OnlineShop {
|
||||||
for(int j=0;j<HilfsArr.length;j++) {
|
for(int j=0;j<HilfsArr.length;j++) {
|
||||||
produktArray[i][j]=HilfsArr[j];
|
produktArray[i][j]=HilfsArr[j];
|
||||||
if(i==0&&j==2)
|
if(i==0&&j==2)
|
||||||
produktArray[i][j]="Gewicht"; //besser für den Druck
|
produktArray[i][j]="Gewicht"; //besser für den Druck weil ich es auf 10 Zeichen beschränke
|
||||||
produktArray[0][HilfsArr.length-1]="Bestand";
|
produktArray[0][HilfsArr.length-1]="Bestand";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -79,7 +79,7 @@ public class OnlineShop {
|
||||||
|
|
||||||
return LagerList;
|
return LagerList;
|
||||||
}
|
}
|
||||||
public boolean[] aufLager() throws FileNotFoundException { //TODO Prüfen ob ich die Methode überhaupt brauche
|
/*public boolean[] aufLager() throws FileNotFoundException { //TODO Prüfen ob ich die Methode überhaupt brauche, da bestand gereicht hat
|
||||||
ArrayList<Produkt> ProduktListe= ÜbertrageListe();
|
ArrayList<Produkt> ProduktListe= ÜbertrageListe();
|
||||||
boolean[] aufLager= new boolean[ProduktListe.size()];
|
boolean[] aufLager= new boolean[ProduktListe.size()];
|
||||||
for(int i=0;i<ProduktListe.size();i++) {
|
for(int i=0;i<ProduktListe.size();i++) {
|
||||||
|
|
@ -89,7 +89,7 @@ public class OnlineShop {
|
||||||
aufLager[i]=false;
|
aufLager[i]=false;
|
||||||
}
|
}
|
||||||
return aufLager;
|
return aufLager;
|
||||||
}
|
}*/
|
||||||
public Produkt suchProdukt(String suche) throws FileNotFoundException {
|
public Produkt suchProdukt(String suche) throws FileNotFoundException {
|
||||||
ArrayList<Produkt>ProduktListe= ÜbertrageListe();
|
ArrayList<Produkt>ProduktListe= ÜbertrageListe();
|
||||||
for(Produkt p : ProduktListe){
|
for(Produkt p : ProduktListe){
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ public class Produkt {
|
||||||
return Math.round((this.preis-(this.preis/(1+this.mwst/100)))*100.0)/100.0;
|
return Math.round((this.preis-(this.preis/(1+this.mwst/100)))*100.0)/100.0;
|
||||||
}
|
}
|
||||||
public double berechneBrutto(){
|
public double berechneBrutto(){
|
||||||
return preis-berechneMwst();
|
return preis+berechneMwst();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* public boolean equals(Object o) {
|
/* public boolean equals(Object o) {
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,49 @@
|
||||||
package pack;
|
package pack;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class Warenkorb {
|
public class Warenkorb {
|
||||||
private ArrayList<Produkt> Artikel;
|
|
||||||
|
private ArrayList<WarenkorbArtikel> Artikel;
|
||||||
|
|
||||||
public Warenkorb() {
|
public Warenkorb() {
|
||||||
|
|
||||||
Artikel = new ArrayList<Produkt>();
|
Artikel = new ArrayList<>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
public Produkt welchesProdukt(int vltID) throws FileNotFoundException {
|
||||||
|
OnlineShop Shop = new OnlineShop();
|
||||||
|
ArrayList<Produkt> produkte = Shop.ÜbertrageListe();
|
||||||
|
|
||||||
public void produktHinzufügen(Produkt p) {
|
for(Produkt p: produkte){
|
||||||
Artikel.add(p);
|
if(p.ID==vltID){
|
||||||
//Todo mit warenkorbartikel verknüpfen
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
}return null;
|
||||||
|
}
|
||||||
|
public boolean aufLager(Produkt p){
|
||||||
|
if(p.Bestand>0)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void produktHinzufügen(Produkt p,int Menge) {
|
||||||
|
Artikel.add(new WarenkorbArtikel(p, Menge));
|
||||||
|
}
|
||||||
|
public boolean ProduktDa (int ID,int Menge) throws FileNotFoundException {
|
||||||
|
Produkt da = welchesProdukt(ID);
|
||||||
|
if(da==null){
|
||||||
|
return false;
|
||||||
|
} boolean genug=aufLager(da);
|
||||||
|
if(genug==true){
|
||||||
|
produktHinzufügen(da,Menge);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,11 @@ 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);
|
static Scanner sc = new Scanner(System.in);
|
||||||
|
Warenkorb wk = new Warenkorb();
|
||||||
|
|
||||||
public static void main(String[] args) throws FileNotFoundException {
|
public void main(String[] args) throws FileNotFoundException {
|
||||||
System.out.println("Willkommen zum DanDan-Shop!");
|
IO.println();
|
||||||
|
System.out.println(">>>>>>>>>>Willkommen zum DanDan-Shop!<<<<<<<<<<");
|
||||||
shop= new OnlineShop();
|
shop= new OnlineShop();
|
||||||
boolean cont = true;
|
boolean cont = true;
|
||||||
|
|
||||||
|
|
@ -22,8 +24,8 @@ public class ShopTUI {
|
||||||
System.out.println("Auf Wiedersehen!");
|
System.out.println("Auf Wiedersehen!");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hauptmenü() throws FileNotFoundException {
|
public boolean hauptmenü() throws FileNotFoundException {
|
||||||
IO.println();
|
|
||||||
IO.println();
|
IO.println();
|
||||||
IO.println(" << H a u p t m e n ü >> ");
|
IO.println(" << H a u p t m e n ü >> ");
|
||||||
IO.println("1.Produktangebot");
|
IO.println("1.Produktangebot");
|
||||||
|
|
@ -41,10 +43,10 @@ public class ShopTUI {
|
||||||
produktsuche();
|
produktsuche();
|
||||||
break;
|
break;
|
||||||
case "3": case "warenkorb": case"Warenkorb":
|
case "3": case "warenkorb": case"Warenkorb":
|
||||||
//Todo warenkorb
|
MeinWarenkorb();
|
||||||
break;
|
break;
|
||||||
case "4": case "bestellungen": case"Bestellungen":
|
case "4": case "bestellungen": case"Bestellungen":
|
||||||
//Todo
|
//Todo vlt lasse ich das ganz beim Warenkorb
|
||||||
break;
|
break;
|
||||||
case "5": case "exit " : case "Exit":
|
case "5": case "exit " : case "Exit":
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -82,30 +84,30 @@ public class ShopTUI {
|
||||||
String suche = sc.nextLine();
|
String suche = sc.nextLine();
|
||||||
int count=0;
|
int count=0;
|
||||||
Produkt vlt=null;
|
Produkt vlt=null;
|
||||||
boolean[] aufLager= shop.aufLager();
|
// boolean[] aufLager= shop.aufLager();
|
||||||
ArrayList<Produkt> ProduktListe= shop.ÜbertrageListe();
|
ArrayList<Produkt> ProduktListe= shop.ÜbertrageListe();
|
||||||
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++) {
|
for(int i=0;i<ProduktListe.size();i++) {
|
||||||
for (int j = 0; j < 5&& j<ProduktListe.get(i).name.length(); j++) {
|
for (int j = 0; j < 5&& j<ProduktListe.get(i).name.length(); j++) {
|
||||||
if (suche.charAt(j) == ProduktListe.get(i).name.charAt(j)){
|
if (suche.charAt(j) == (ProduktListe.get(i).name).charAt(j)){
|
||||||
count++;
|
count++;
|
||||||
if(count==5){
|
if(count==4){
|
||||||
vlt=ProduktListe.get(i);
|
vlt=ProduktListe.get(i);
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
} count=0;
|
} count=0;
|
||||||
}
|
}
|
||||||
if(count==5) {
|
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);
|
IO.println("Unser Bestand beträgt "+ vlt.Bestand);
|
||||||
}*/
|
}else
|
||||||
IO.println("Das gesuchte Produkt wurde leider nicht gefunden");
|
IO.println("Das gesuchte Produkt wurde leider nicht gefunden");
|
||||||
} else {
|
} else {
|
||||||
IO.println("Hier ist das Produkt: " + gefunden.name + " " + gefunden.preis + " €");
|
IO.println("Hier ist das Produkt: " + gefunden.name + " " + gefunden.preis + " € zzgl. " + gefunden.mwst+" % mwst");
|
||||||
if(gefunden.Bestand ==0){
|
if(gefunden.Bestand ==0){
|
||||||
IO.println("Das Produkt ist aber leider zur Zeit nicht verfügbar");
|
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
|
//Todo hier trimen oder splite damit der user nicht sowas wie 7l hinzufügen muss
|
||||||
|
|
@ -114,11 +116,47 @@ public class ShopTUI {
|
||||||
//Todo hinzufügfen ermöglichen
|
//Todo hinzufügfen ermöglichen
|
||||||
|
|
||||||
}
|
}
|
||||||
} public void MeinWarenkorb(){
|
|
||||||
//Todo hier hinzufügen, entfernen oder menge ändern ermöglichen
|
|
||||||
}
|
}
|
||||||
public void bestellen(){
|
public void bestellen(){
|
||||||
//Hier alle infos wie name und addresse abfangen
|
//Hier alle infos wie name und addresse abfangen
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void MeinWarenkorb() throws FileNotFoundException {
|
||||||
|
Warenkorb warenkorb;
|
||||||
|
String Wahl;
|
||||||
|
do {
|
||||||
|
IO.print(">>Warenkorb-Menü<<");
|
||||||
|
IO.println("1. Artikel hinzüfugen [Bitte hierfür am besten die Produkt ID benutzen!]");
|
||||||
|
IO.println("2. Meinen Warenkorb anzeigen bzw Bestellung aufgeben");
|
||||||
|
IO.println("3. Etwas aus den Warenkorb löschen");
|
||||||
|
IO.println("4. Die Menge reduzieren");
|
||||||
|
IO.println("5. back");
|
||||||
|
IO.print(">>");
|
||||||
|
Wahl = sc.nextLine();
|
||||||
|
switch (Wahl) {
|
||||||
|
case "1":
|
||||||
|
hinzufuegen();
|
||||||
|
break;
|
||||||
|
case "2":
|
||||||
|
}
|
||||||
|
} while (!Wahl.equals("5")||Wahl.equalsIgnoreCase("back"));
|
||||||
|
|
||||||
|
|
||||||
|
} public void hinzufuegen() throws FileNotFoundException {
|
||||||
|
IO.println("Bitte geben sie eine ProduktID ein");
|
||||||
|
IO.print("ID:");
|
||||||
|
int ID=sc.nextInt();
|
||||||
|
IO.println("Wieviel wollen sie hinzufügen?");
|
||||||
|
IO.print("Menge:");
|
||||||
|
int Menge=sc.nextInt();
|
||||||
|
sc.nextLine();
|
||||||
|
boolean geklappt= wk.ProduktDa(ID,Menge);
|
||||||
|
if(geklappt){
|
||||||
|
IO.println("Das Produkt wurde zum Warenkorb hinzugefügt!!");
|
||||||
|
}else
|
||||||
|
IO.println("Die ID existiert nicht oder das Produkt ist leider nicht auf Lager");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue