diff --git a/OS-Abgabe/src/backend/Bestellung.java b/OS-Abgabe/src/backend/Bestellung.java new file mode 100644 index 0000000..a1c89e9 --- /dev/null +++ b/OS-Abgabe/src/backend/Bestellung.java @@ -0,0 +1,5 @@ +package backend; + +public class Bestellung { + +} diff --git a/OS-Abgabe/src/backend/OnlineShop.java b/OS-Abgabe/src/backend/OnlineShop.java new file mode 100644 index 0000000..facb44b --- /dev/null +++ b/OS-Abgabe/src/backend/OnlineShop.java @@ -0,0 +1,47 @@ +package backend; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.Scanner; +import java.io.File; + + + +public class OnlineShop { + public ArrayList lager; + + public OnlineShop() throws FileNotFoundException { + lager = new ArrayList(); + + Scanner sc = new Scanner(new File("././resources/produkte.csv")); + + if (sc.hasNextLine()) sc.nextLine(); + + while(sc.hasNextLine() ) { + String zeile = sc.nextLine(); + String[] teile = zeile.split(","); + + int id = Integer.parseInt(teile[0]); + String name = teile[1]; + double gewicht = Double.parseDouble(teile[2]); + double preis = Double.parseDouble(teile[3]); + int mwst = Integer.parseInt(teile[4]); + int bestand = Integer.parseInt(teile[5]); + + Produkt p = new Produkt(id, name, gewicht, preis, mwst, bestand); + + lager.add(p); + + } + + sc.close(); + } + + public String[] produktListe() { + String[] produkt = new String[lager.size()]; + for(int i = 0; i < lager.size(); i++) { + produkt[i] = lager.get(i).toString(); + } + + return produkt; + } +} diff --git a/OS-Abgabe/src/backend/Produkt.java b/OS-Abgabe/src/backend/Produkt.java new file mode 100644 index 0000000..199796f --- /dev/null +++ b/OS-Abgabe/src/backend/Produkt.java @@ -0,0 +1,71 @@ +package backend; + +public class Produkt { + public int id; + public String name; + public double gewicht; + public double preis; + public int mwst; + public int bestand; + + public Produkt(int id, String name, double gewicht, double preis, int mwst, int bestand) { + this.id = id; + this.name = name; + this.gewicht = gewicht; + this.preis = preis; + this.mwst = mwst; + this.bestand = bestand; + } + + public String getName() { + return this.name; + } + + public void setName(String neu) { + this.name = neu; + } + + public String toString() { + return id + " | " + name + " | " + preis + "€"; + } + + public boolean equals(Produkt o) { + if (!(o instanceof Produkt)) + return false; + + if (o == null) + return false; + + if (!this.name.equals(((Produkt)o).name) + || this.preis != ((Produkt)o).preis) + return false; + + return true; + } + + @Override + public int hashCode() { + return Objects.hash(name, preis); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Produkt other = (Produkt) obj; + return Objects.equals(name, other.name) + && Double.doubleToLongBits(preis) == Double.doubleToLongBits(other.preis); + } + + + +} + + + + + \ No newline at end of file diff --git a/OS-Abgabe/src/backend/Warenkorb.java b/OS-Abgabe/src/backend/Warenkorb.java new file mode 100644 index 0000000..aec4d40 --- /dev/null +++ b/OS-Abgabe/src/backend/Warenkorb.java @@ -0,0 +1,28 @@ +package backend; +import java.util.ArrayList; + +public class Warenkorb { + private ArrayList inhalt; + + public Warenkorb() { + inhalt = new ArrayList(); + } + + public void produktHinzufügen(Produkt p) { + inhalt.add(p); + } + + public double berechneGesamtpreis() { + double preis = 0; + for (Produkt p : inhalt) + preis+= p.preis; + return preis; + } + + public void anzeigen() { + System.out.println("(。•◡•。) Hier ist Ihr aktueller Warenkorb: "); + for (Produkt p : inhalt) + System.out.println(p); + System.out.println("Betrag: " + berechneGesamtpreis() + "€ ૮˶ᵔᵕᵔ˶ა"); + } +} diff --git a/OS-Abgabe/src/backend/WarenkorbPosition.java b/OS-Abgabe/src/backend/WarenkorbPosition.java new file mode 100644 index 0000000..2bb9e90 --- /dev/null +++ b/OS-Abgabe/src/backend/WarenkorbPosition.java @@ -0,0 +1,5 @@ +package backend; + +public class WarenkorbPosition { + +} diff --git a/OS-Abgabe/src/tui/shopTUI.java b/OS-Abgabe/src/tui/shopTUI.java new file mode 100644 index 0000000..d59c1a0 --- /dev/null +++ b/OS-Abgabe/src/tui/shopTUI.java @@ -0,0 +1,69 @@ +package tui; +import backend.OnlineShop; +import backend.Produkt; +import java.util.Scanner; +import java.io.FileNotFoundException; + + +public class shopTUI { + + private static OnlineShop shop; + private static Scanner sc = new Scanner(System.in); + + public static void main(String[] args) throws FileNotFoundException { + System.out.println("Willkommen bei Onami! („•֊•„)੭"); + + shop = new OnlineShop(); + + angebot(); + + suche(); + + System.out.println("Auf Wiedersehen! (づ˶•༝•˶)づ "); + } + + public static void hauptmenü() { + // TODO: hier ein erstes Menü mit bspw. + // Produktangebot + // Produktsuche + // Warenkorbanzeige + // evtl. Bestellung (kann auch über Warenkorb realisiert werden) + // Exit + } + + public static void angebot() { + System.out.println("૮ ྀིᴗ͈.ᴗ͈ ྀིა Was wir Ihnen anbieten:"); + System.out.println(); + + String[] produkte = shop.produktListe(); + for (int i = 0; i < produkte.length; i++) + System.out.println(produkte[i]); + } + + public static void suche() { + System.out.println(); + System.out.println("(˶˃ᵕ˂˶) Was suchen Sie? "); + String suchbegriff = sc.nextLine().toLowerCase(); + if (suchbegriff.length() == 0) return; + + boolean gefunden = false; + + for (int artnr = 0; artnr < shop.lager.size(); artnr++) { + Produkt p = shop.lager.get(artnr); + + for (int i = 0; i <= p.name.length() - suchbegriff.length(); i++) { + if (p.name.substring(i, i + suchbegriff.length()).toLowerCase().equals(suchbegriff)) { + if(!gefunden) { + System.out.println(); + System.out.println(); + System.out.println("(˶ˆᗜˆ˵) Wir haben folgenden Treffer: "); + } + System.out.println(p); + gefunden = true; + break; + } + } + } + if (!gefunden) System.out.println("Leider keine Treffer (˃̣̣̥ᯅ˂̣̣̥)"); + } +}