online-shop
commit
dc8b13aada
|
|
@ -0,0 +1,3 @@
|
||||||
|
/bin/
|
||||||
|
/.classpath
|
||||||
|
/.project
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
encoding/<project>=UTF-8
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=23
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=23
|
||||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||||
|
org.eclipse.jdt.core.compiler.release=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.source=23
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
package OnlineShop.Main;
|
||||||
|
import OnlineShop.UI.TUI;
|
||||||
|
import OnlineShop.domain.ExceptionsKlassen.*;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
new TUI();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,152 @@
|
||||||
|
package OnlineShop.UI;
|
||||||
|
import java.util.Scanner;
|
||||||
|
import OnlineShop.domain.*;
|
||||||
|
import OnlineShop.domain.ExceptionsKlassen.*;
|
||||||
|
|
||||||
|
|
||||||
|
public class TUI {
|
||||||
|
|
||||||
|
private Kaufhalle kaufhalle;
|
||||||
|
private Scanner eingabe = new Scanner(System.in);
|
||||||
|
|
||||||
|
private String optionAuswahl;
|
||||||
|
|
||||||
|
public TUI() throws Exception {
|
||||||
|
this.kaufhalle = new Kaufhalle();
|
||||||
|
startProgramm();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startProgramm() throws Exception {
|
||||||
|
System.out.println("<< Willkommen in meinem Online Shop >>");
|
||||||
|
System.out.println();
|
||||||
|
if (kaufhalle.produkteLadenImSystem()) {
|
||||||
|
System.out.println("Meine aktuelle Produkte: ");
|
||||||
|
|
||||||
|
for (String p : kaufhalle.zeigeProdukte())
|
||||||
|
System.out.println(p);
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
shwoOptions();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void shwoOptions() throws Exception {
|
||||||
|
boolean programmAktive = true;
|
||||||
|
while (programmAktive) {
|
||||||
|
System.out.println("Wählen Sie bitte ein Option aus: ");
|
||||||
|
System.out.println("1. Produkte auswählen");
|
||||||
|
System.out.print("> ");
|
||||||
|
optionAuswahl = eingabe.nextLine();
|
||||||
|
|
||||||
|
switch (optionAuswahl) {
|
||||||
|
case "1":
|
||||||
|
WarenkorbEditieren();
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WarenkorbEditieren() throws Exception {
|
||||||
|
boolean einkaufAktive = true;
|
||||||
|
String weiterEinkaufen;
|
||||||
|
while (einkaufAktive) {
|
||||||
|
System.out.println("1. Prpdukte auswählen und zu Ihrem Warenkorb senden");
|
||||||
|
System.out.print("> ");
|
||||||
|
optionAuswahl = eingabe.nextLine();
|
||||||
|
|
||||||
|
switch(optionAuswahl) {
|
||||||
|
case "1":
|
||||||
|
while (true) {
|
||||||
|
System.out.print("Name der Produkt: > ");
|
||||||
|
String produktName = eingabe.nextLine();
|
||||||
|
System.out.print("Menge > ");
|
||||||
|
int menge = eingabe.nextInt();
|
||||||
|
try {
|
||||||
|
kaufhalle.addProduktZuWarenkorb(produktName,menge);
|
||||||
|
} catch (ProduktNichtGefundenException e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Weitere Produkte auswählen Ja/Nein");
|
||||||
|
System.out.print(">");
|
||||||
|
weiterEinkaufen = eingabe.nextLine();
|
||||||
|
if (weiterEinkaufen.equalsIgnoreCase("ja"))
|
||||||
|
continue;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// private void ProdukteAuwählenUI() throws Exception {
|
||||||
|
// boolean einkaufAktive = true;
|
||||||
|
// String weiterEinkaufen;
|
||||||
|
// int menge;
|
||||||
|
// while (einkaufAktive) {
|
||||||
|
// System.out.println("Wählen Sie bitte ein Option aus: ");
|
||||||
|
// System.out.println("1. Prpdukte auswählen und zu Ihrem Warenkorb senden");
|
||||||
|
// System.out.println("2. Prpdukte aus dem Warenkorb löschen");
|
||||||
|
// System.out.println("3. Zurück zum Hauptmenu");
|
||||||
|
// System.out.print("> ");
|
||||||
|
// optionAuswahl = eingabe.nextLine();
|
||||||
|
// switch (optionAuswahl) {
|
||||||
|
// case "1":
|
||||||
|
// while (true) {
|
||||||
|
// System.out.print("Name der Produkt: > ");
|
||||||
|
// String produktName = eingabe.nextLine();
|
||||||
|
//
|
||||||
|
// System.out.print("Menge > ");
|
||||||
|
// menge = eingabe.nextInt();
|
||||||
|
// try {
|
||||||
|
// kaufhalle.addProduktZuWarenkorb(produktName,menge);
|
||||||
|
// for (String p : kaufhalle.zeigeProdukte())
|
||||||
|
// System.out.println(p);
|
||||||
|
// } catch (ProduktNichtGefundenException e) {
|
||||||
|
// System.out.println(e.getMessage());
|
||||||
|
// }
|
||||||
|
// System.out.println(
|
||||||
|
// "Anzahl Ihre ausgewählte Produkte: " + kaufhalle.getAnzahlDerAusgewählteProdukte());
|
||||||
|
// System.out.println("Weitere Produkte auswählen Ja/Nein");
|
||||||
|
// System.out.print(">");
|
||||||
|
// weiterEinkaufen = eingabe.nextLine();
|
||||||
|
// if (weiterEinkaufen.equalsIgnoreCase("ja"))
|
||||||
|
// continue;
|
||||||
|
// else
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// break;
|
||||||
|
//
|
||||||
|
// case "2":
|
||||||
|
// while (true) {
|
||||||
|
// System.out.print("Name der Produkt: > ");
|
||||||
|
// String produktName = eingabe.nextLine();
|
||||||
|
//// if (kaufhalle.loescheProduktausWarenkorb(produktName) == true) {
|
||||||
|
//// System.out.println("Produkt erfolgreich gelöscht");
|
||||||
|
//// System.out.println(
|
||||||
|
//// "Anzahl Ihre ausgewählte Produkte: " + kaufhalle.getAnzahlDerAusgewählteProdukte());
|
||||||
|
//// } else
|
||||||
|
//// System.out.println("Produkt ist nicht in Ihrem Warenkorb");
|
||||||
|
//
|
||||||
|
// System.out.println("Weiter Produkte aus dem Wrenkorb löschen Ja/Nein");
|
||||||
|
// System.out.print(">");
|
||||||
|
// String weitereProdukteLoeschen = eingabe.nextLine();
|
||||||
|
// if (weitereProdukteLoeschen.equalsIgnoreCase("ja"))
|
||||||
|
// continue;
|
||||||
|
// else
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// break;
|
||||||
|
//
|
||||||
|
// case "3":
|
||||||
|
// System.out.println("Anzahl Ihre ausgewählte Produkte: " + kaufhalle.getAnzahlDerAusgewählteProdukte());
|
||||||
|
// shwoOptions();
|
||||||
|
// break;
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// System.out.println("Anzahl Ihre ausgewählte Produkte: " + kaufhalle.getAnzahlDerAusgewählteProdukte());
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,80 @@
|
||||||
|
package OnlineShop.domain;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class Bestellung {
|
||||||
|
|
||||||
|
private double kosten;
|
||||||
|
private String formattedkosten;
|
||||||
|
private String kundeName;
|
||||||
|
private int gewicht;
|
||||||
|
private double versandKosten;
|
||||||
|
private ArrayList<WarenkorbMenge> tempProdukt;
|
||||||
|
private Date date;
|
||||||
|
|
||||||
|
public Bestellung(ArrayList<WarenkorbMenge> produkts, String kundeName) {
|
||||||
|
this.tempProdukt = produkts;
|
||||||
|
this.kundeName = kundeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getKosten() {
|
||||||
|
for (WarenkorbMenge p : tempProdukt) {
|
||||||
|
kosten += p.getProdukt().getPreis();
|
||||||
|
kosten *= p.getMenge();
|
||||||
|
}
|
||||||
|
formattedkosten = String.format("%.2f", kosten);
|
||||||
|
formattedkosten = formattedkosten.replace(",", "."); // Ersetzt das Komma durch einen Punkt
|
||||||
|
|
||||||
|
return Double.parseDouble(formattedkosten);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getGewicht() {
|
||||||
|
gewicht = 0;
|
||||||
|
for (WarenkorbMenge p : tempProdukt) {
|
||||||
|
gewicht += p.getProdukt().getGewicht();
|
||||||
|
gewicht *= p.getMenge();
|
||||||
|
}
|
||||||
|
|
||||||
|
return gewicht;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getVersandKosten() {
|
||||||
|
getGewicht();
|
||||||
|
double gewichtInKg = gewicht / 1000.0;
|
||||||
|
System.out.println("gewichtInKg: " + gewichtInKg);
|
||||||
|
|
||||||
|
if (gewichtInKg < 1)
|
||||||
|
versandKosten += 5;
|
||||||
|
|
||||||
|
else if (gewichtInKg >= 1 && gewichtInKg <= 2.5)
|
||||||
|
versandKosten += 8;
|
||||||
|
|
||||||
|
else
|
||||||
|
versandKosten += 10;
|
||||||
|
|
||||||
|
return versandKosten;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getGesamtKosten() {
|
||||||
|
double gesmatKosten = kosten + versandKosten;
|
||||||
|
String formatted = String.format("%.2f", gesmatKosten);
|
||||||
|
formatted = formatted.replace(",", "."); // Ersetzt das Komma durch einen Punkt
|
||||||
|
return Double.parseDouble(formatted);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getDate() {
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDate(Date date) {
|
||||||
|
this.date = date;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Kunde= " + kundeName + ", kosten=" + formattedkosten + ", versandKosten=" + versandKosten + ", date="
|
||||||
|
+ date;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
package OnlineShop.domain.ExceptionsKlassen;
|
||||||
|
|
||||||
|
public class KeineProdukteImWarenkorb extends Exception {
|
||||||
|
|
||||||
|
public KeineProdukteImWarenkorb(String error){
|
||||||
|
super(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
package OnlineShop.domain.ExceptionsKlassen;
|
||||||
|
|
||||||
|
public class LeereEingabeException extends Exception {
|
||||||
|
|
||||||
|
public LeereEingabeException (String error){
|
||||||
|
super(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
package OnlineShop.domain.ExceptionsKlassen;
|
||||||
|
|
||||||
|
public class ProduktNichtGefundenException extends Exception {
|
||||||
|
|
||||||
|
public ProduktNichtGefundenException(String error){
|
||||||
|
super(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
package OnlineShop.domain.JTest;
|
||||||
|
|
||||||
|
|
||||||
|
import org.junit.*;
|
||||||
|
|
||||||
|
import OnlineShop.domain.*;
|
||||||
|
|
||||||
|
class JTest {
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test() throws Exception {
|
||||||
|
Kaufhalle kaufhalle = new Kaufhalle();
|
||||||
|
kaufhalle.produkteLadenImSystem();
|
||||||
|
kaufhalle.addProduktZuWarenkorb("hut", 10);
|
||||||
|
|
||||||
|
kaufhalle.addProduktZuWarenkorb("hut", 5);
|
||||||
|
|
||||||
|
kaufhalle.loginKunde("Obai", "Mannheim");
|
||||||
|
kaufhalle.bestellen();
|
||||||
|
kaufhalle.speichereBestellung();
|
||||||
|
|
||||||
|
kaufhalle.addProduktZuWarenkorb("hut", 5);
|
||||||
|
kaufhalle.loginKunde("Omar", "Mannheim");
|
||||||
|
kaufhalle.bestellen();
|
||||||
|
kaufhalle.speichereBestellung();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,116 @@
|
||||||
|
package OnlineShop.domain;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.util.*;
|
||||||
|
import OnlineShop.domain.ExceptionsKlassen.*;
|
||||||
|
|
||||||
|
public class Kaufhalle {
|
||||||
|
private ArrayList<Produkt> produkte;
|
||||||
|
private ArrayList<Bestellung> bestellungen;
|
||||||
|
private Kunde kunde;
|
||||||
|
private Bestellung akteulleBestellung;
|
||||||
|
|
||||||
|
public Kaufhalle() throws FileNotFoundException {
|
||||||
|
this.produkte = new ArrayList<>();
|
||||||
|
this.kunde = new Kunde();
|
||||||
|
this.bestellungen = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean produkteLadenImSystem() throws FileNotFoundException {
|
||||||
|
return produkteLaden.produkteLaden(produkte);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean addProduktZuWarenkorb(String Produktname, int menge)
|
||||||
|
throws ProduktNichtGefundenException, Exception {
|
||||||
|
Produkt neueProdukt = findeProduktImKaufhalle(Produktname);
|
||||||
|
if (neueProdukt == null)
|
||||||
|
throw new ProduktNichtGefundenException("Produkt ist nicht Verfügbar!");
|
||||||
|
|
||||||
|
if (menge > neueProdukt.getBestand())
|
||||||
|
throw new Exception("Wir haben nicht genug Produktmenge im Lager!");
|
||||||
|
|
||||||
|
WarenkorbMenge wp = kunde.getWarenKorb().findWarenkorbMenge(Produktname);
|
||||||
|
if (wp != null)
|
||||||
|
wp.setMenge(wp.getMenge() + menge);
|
||||||
|
|
||||||
|
else {
|
||||||
|
WarenkorbMenge neueWarenkorbMenge = new WarenkorbMenge();
|
||||||
|
neueWarenkorbMenge.addProdukt(neueProdukt, menge);
|
||||||
|
kunde.getWarenKorb().addProdukt(neueWarenkorbMenge);
|
||||||
|
}
|
||||||
|
|
||||||
|
neueProdukt.setBestand(neueProdukt.getBestand() - menge);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean mengeaendern(String Produktname, int menge) throws ProduktNichtGefundenException {
|
||||||
|
WarenkorbMenge akteulleProdukt = kunde.getWarenKorb().findWarenkorbMenge(Produktname);
|
||||||
|
|
||||||
|
if (akteulleProdukt == null)
|
||||||
|
throw new ProduktNichtGefundenException("Sie haben das Produkt nicht in Ihrem Warenkorb");
|
||||||
|
|
||||||
|
if (menge > akteulleProdukt.getProdukt().getBestand())
|
||||||
|
throw new ProduktNichtGefundenException("Wir haben nicht genug Produktmenge im Lager!");
|
||||||
|
|
||||||
|
akteulleProdukt.setMenge(menge);
|
||||||
|
akteulleProdukt.getProdukt().setBestand(akteulleProdukt.getProdukt().getBestand() - menge);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean loescheProdukt(String Produktname) throws ProduktNichtGefundenException {
|
||||||
|
WarenkorbMenge produktToBERemoved = kunde.getWarenKorb().findWarenkorbMenge(Produktname);
|
||||||
|
|
||||||
|
if (produktToBERemoved == null)
|
||||||
|
throw new ProduktNichtGefundenException("Sie haben das Produkt nicht in Ihrem Warenkorb");
|
||||||
|
|
||||||
|
return kunde.getWarenKorb().getProdukte().remove(produktToBERemoved);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean bestellen() throws ProduktNichtGefundenException {
|
||||||
|
if (kunde.getWarenKorb().getProdukte().size() == 0)
|
||||||
|
throw new ProduktNichtGefundenException("Sie haben das Produkt nicht in Ihrem Warenkorb");
|
||||||
|
|
||||||
|
akteulleBestellung = new Bestellung(kunde.getWarenKorb().getProdukte(), kunde.getName());
|
||||||
|
akteulleBestellung.getKosten();
|
||||||
|
akteulleBestellung.getVersandKosten();
|
||||||
|
kunde.getWarenKorb().getProdukte().clear();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean speichereBestellung() {
|
||||||
|
this.akteulleBestellung.setDate(new Date());
|
||||||
|
bestellungen.add(akteulleBestellung);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean loginKunde(String name, String anschrift) throws LeereEingabeException {
|
||||||
|
|
||||||
|
if (name.isEmpty() || anschrift.isEmpty())
|
||||||
|
throw new LeereEingabeException("Sie müssen Name sowie anschrift eingeben");
|
||||||
|
|
||||||
|
kunde.setName(name);
|
||||||
|
kunde.setAnschrift(anschrift);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Produkt findeProduktImKaufhalle(String Produktname) {
|
||||||
|
|
||||||
|
for (Produkt p : produkte)
|
||||||
|
if (p.getName().equalsIgnoreCase(Produktname))
|
||||||
|
return p;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> zeigeProdukte() {
|
||||||
|
ArrayList<String> allProdukte = new ArrayList<>();
|
||||||
|
int index = 1;
|
||||||
|
for (Produkt p : produkte)
|
||||||
|
allProdukte.add(index++ + ".Produkt: " + p.toString());
|
||||||
|
|
||||||
|
return allProdukte;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
package OnlineShop.domain;
|
||||||
|
|
||||||
|
public class Kunde {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private String anschrift;
|
||||||
|
private Warenkorb warenKorb;
|
||||||
|
|
||||||
|
public Kunde(String name, String anschrift) {
|
||||||
|
this.name = name;
|
||||||
|
this.anschrift = anschrift;
|
||||||
|
this.warenKorb = new Warenkorb();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Kunde() {
|
||||||
|
this(null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAnschrift() {
|
||||||
|
return anschrift;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAnschrift(String anschrift) {
|
||||||
|
this.anschrift = anschrift;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Warenkorb getWarenKorb() {
|
||||||
|
return warenKorb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
package OnlineShop.domain;
|
||||||
|
|
||||||
|
public class Produkt {
|
||||||
|
private String name;
|
||||||
|
private String beschreibung;
|
||||||
|
private double preis;
|
||||||
|
private int gewicht;
|
||||||
|
private int bestand;
|
||||||
|
|
||||||
|
public Produkt(String name, String beschreibung, double preis, int gewicht, int bestand) {
|
||||||
|
|
||||||
|
this.name = name;
|
||||||
|
this.beschreibung = beschreibung;
|
||||||
|
this.preis = preis;
|
||||||
|
this.gewicht = gewicht;
|
||||||
|
this.bestand = bestand;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBeschreibung() {
|
||||||
|
return beschreibung;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getPreis() {
|
||||||
|
return preis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getGewicht() {
|
||||||
|
return gewicht;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBestand() {
|
||||||
|
return bestand;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBestand(int bestand) {
|
||||||
|
this.bestand = bestand;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return String.format("name=%s, beschreibung=%s, preis=%.2f, gewicht=%d, bestand=%d", name, beschreibung, preis,
|
||||||
|
gewicht, bestand);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
package OnlineShop.domain;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import OnlineShop.domain.ExceptionsKlassen.KeineProdukteImWarenkorb;
|
||||||
|
|
||||||
|
public class Warenkorb {
|
||||||
|
private ArrayList<WarenkorbMenge> produkte;
|
||||||
|
|
||||||
|
Warenkorb() {
|
||||||
|
this.produkte = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean addProdukt(WarenkorbMenge neueWarenkorbMenge) {
|
||||||
|
produkte.add(neueWarenkorbMenge);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<WarenkorbMenge> getProdukte() {
|
||||||
|
return produkte;
|
||||||
|
}
|
||||||
|
|
||||||
|
public WarenkorbMenge findWarenkorbMenge(String name) {
|
||||||
|
|
||||||
|
for (WarenkorbMenge wp : produkte)
|
||||||
|
if (wp.getProdukt().getName().equalsIgnoreCase(name))
|
||||||
|
return wp;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
package OnlineShop.domain;
|
||||||
|
|
||||||
|
public class WarenkorbMenge {
|
||||||
|
private Produkt produkt;
|
||||||
|
private int menge;
|
||||||
|
|
||||||
|
public void addProdukt(Produkt p, int menge) {
|
||||||
|
|
||||||
|
this.produkt = p;
|
||||||
|
this.menge = menge;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Produkt getProdukt() {
|
||||||
|
return produkt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProdukt(Produkt produkt) {
|
||||||
|
this.produkt = produkt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMenge() {
|
||||||
|
return menge;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMenge(int menge) {
|
||||||
|
this.menge = menge;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return produkt.toString() + ", menge=" + menge;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
Name;Beschreibung;Preis;Gewicht;Bestand
|
||||||
|
Gieskanne;Premium Gärtner-Gieskanne;3,99;250,00;17,00
|
||||||
|
Hut;Perfekt für die Hutablage;21,98;120,00;123,00
|
||||||
|
Dosenwurst;LWWRSCHT: das Pfälzer Original, nur kurz im Angebot;3,99;200,00;7,00
|
||||||
|
Gartenschlauch;10 m, dehnbar bis auf die doppelte Länge;18,99;1300,00;23,00
|
||||||
|
Schraubenset;100 zufällig ausgewählte Schrauben;2,99;287,00;99,00
|
||||||
|
Akkuschrauber;Mit extra großem Drehmoment;25,00;900,00;13,00
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
package OnlineShop.domain;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class produkteLaden {
|
||||||
|
|
||||||
|
public static boolean produkteLaden(ArrayList<Produkt> produkte) throws FileNotFoundException {
|
||||||
|
Scanner sc = new Scanner(new File(
|
||||||
|
"C:\\Users\\obaya\\git\\Programmierung2\\Programmierung2\\src\\OnlineShop\\domain\\produkte.csv"));
|
||||||
|
|
||||||
|
int cnt = 0;
|
||||||
|
while (sc.hasNextLine()) {
|
||||||
|
String produkt = sc.nextLine();
|
||||||
|
|
||||||
|
if (produkt.startsWith("Name"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
String[] spalten = produkt.split(";");
|
||||||
|
spalten[2] = spalten[2].replaceAll(",", ".");
|
||||||
|
spalten[3] = spalten[3].substring(0, spalten[3].indexOf(","));
|
||||||
|
spalten[4] = spalten[4].substring(0, spalten[4].indexOf(","));
|
||||||
|
|
||||||
|
produkte.add(new Produkt(spalten[0], spalten[1], Float.parseFloat(spalten[2]), Integer.parseInt(spalten[3]),
|
||||||
|
Integer.parseInt(spalten[4])));
|
||||||
|
cnt++;
|
||||||
|
}
|
||||||
|
|
||||||
|
sc.close();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
module OnlineShop {
|
||||||
|
requires java.desktop;
|
||||||
|
requires junit;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue