diff --git a/src/OnlineShop.java b/src/OnlineShop.java new file mode 100644 index 0000000..9a839d8 --- /dev/null +++ b/src/OnlineShop.java @@ -0,0 +1,69 @@ +import java.io.File; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.Scanner; + +public class OnlineShop { + public ArrayList lager; + Warenkorb warenkorb = new Warenkorb(); + + public OnlineShop() throws FileNotFoundException { + lager = new ArrayList(); + umwandlung(lager); + } + + public static ArrayList readFile(String path) throws FileNotFoundException { + + ArrayList lines = new ArrayList<>(); + Scanner sc = new Scanner(new File(path)); + + while (sc.hasNextLine()) { + lines.add(sc.nextLine()); + } + + sc.close(); + + return lines; + } + + public static ArrayList umwandlung (ArrayList liste) throws FileNotFoundException { + ArrayList resource = readFile("resources\\produkte.csv"); + for (int i = 1; i < resource.size(); i++) { + String[] teile = resource.get(i).split(","); + Produkt produkt = new Produkt(); + produkt.produktNr = Integer.parseInt(teile[0]); + produkt.name = teile[1]; + produkt.gewicht = Double.parseDouble(teile[2]); + produkt.preis = Double.parseDouble(teile[3]); + produkt.mwSteuer = Integer.parseInt(teile[4]); + produkt.lagerbestand = Integer.parseInt(teile[5]); + + liste.add(produkt); + } + return liste; + + } + + public String[] produkteListe() throws FileNotFoundException { + String[] produkt = new String[lager.size()]; + for (int i = 0; i < lager.size(); i++) { + produkt[i] = lager.get(i).toString(); + } + return produkt; + } + + public void inWarenkorb(int produktNr, int menge){ + Produkt produkt = lager.get(produktNr-1); + warenkorb.produkte.add(produkt); + warenkorb.menge.add(menge); + + } + + public void warenkorbAusgabe(){ + + System.out.println("Der aktuelle Warenkorb sieht so aus: "); + System.out.println(warenkorb); + + } + +} diff --git a/src/Produkt.java b/src/Produkt.java new file mode 100644 index 0000000..860bf40 --- /dev/null +++ b/src/Produkt.java @@ -0,0 +1,44 @@ +public class Produkt { + int produktNr; + String name; + double gewicht; + double preis; + int mwSteuer; + int lagerbestand; + + + public Produkt(int produktNr, String name, double gewicht, double preis, int mwSteuer, int lagerbestand ) { + this.produktNr = produktNr; + this.name = name; + this.gewicht = gewicht; + this.preis = preis; + this.mwSteuer = mwSteuer; + this.lagerbestand = lagerbestand; + } + + public Produkt() { + } + + public int getProduktNr(){ + return produktNr; + } + public String getName() { + return name; + } + public double getGewicht() { + return gewicht; + } + public double getPreis() { + return preis; + } + public int getMwSteuer() { + return mwSteuer; + } + public int getLagerbestand() { + return lagerbestand; + } + + public String toString(){ + return this.produktNr + ", " + this.name + ", " + this.gewicht + ", " + this.preis + ", " + this.mwSteuer + ", " + this.lagerbestand; + } +} diff --git a/src/Warenkorb.java b/src/Warenkorb.java new file mode 100644 index 0000000..a48c523 --- /dev/null +++ b/src/Warenkorb.java @@ -0,0 +1,19 @@ +import java.util.ArrayList; + +public class Warenkorb { + ArrayList menge = new ArrayList<>(); + ArrayList produkte = new ArrayList<>(); + + public Warenkorb() + { + } + public Warenkorb(ArrayList menge, ArrayList produkte) { + this.menge = menge; + this.produkte = produkte; + } + + public String toString() { + + return this.menge.toString() + " Stück | " + this.produkte.toString(); + } +}