Grundgerüst (ShopTUI + Objekte OnlineShop, Warenkorb, Produkt und die jeweilige Struktur initialisieren)
parent
3e136fab85
commit
8253853a0c
|
|
@ -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<Produkt> lager;
|
||||
Warenkorb warenkorb = new Warenkorb();
|
||||
|
||||
public OnlineShop() throws FileNotFoundException {
|
||||
lager = new ArrayList<Produkt>();
|
||||
umwandlung(lager);
|
||||
}
|
||||
|
||||
public static ArrayList<String> readFile(String path) throws FileNotFoundException {
|
||||
|
||||
ArrayList<String> lines = new ArrayList<>();
|
||||
Scanner sc = new Scanner(new File(path));
|
||||
|
||||
while (sc.hasNextLine()) {
|
||||
lines.add(sc.nextLine());
|
||||
}
|
||||
|
||||
sc.close();
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
public static ArrayList<Produkt> umwandlung (ArrayList<Produkt> liste) throws FileNotFoundException {
|
||||
ArrayList<String> 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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
import java.util.ArrayList;
|
||||
|
||||
public class Warenkorb {
|
||||
ArrayList<Integer> menge = new ArrayList<>();
|
||||
ArrayList<Produkt> produkte = new ArrayList<>();
|
||||
|
||||
public Warenkorb()
|
||||
{
|
||||
}
|
||||
public Warenkorb(ArrayList<Integer> menge, ArrayList<Produkt> produkte) {
|
||||
this.menge = menge;
|
||||
this.produkte = produkte;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
||||
return this.menge.toString() + " Stück | " + this.produkte.toString();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue