Die Bruttopreis berrechnung erfolgt jetzt in der Klasse Produkt.
parent
8935b59916
commit
2a017af837
|
|
@ -14,7 +14,7 @@ public class OnlineShop {
|
|||
umwandlung(lager);
|
||||
}
|
||||
|
||||
public static ArrayList<String> readFile(String path) throws FileNotFoundException {
|
||||
public ArrayList<String> readFile(String path) throws FileNotFoundException {
|
||||
|
||||
ArrayList<String> lines = new ArrayList<>();
|
||||
Scanner sc = new Scanner(new File(path));
|
||||
|
|
@ -28,7 +28,7 @@ public class OnlineShop {
|
|||
return lines;
|
||||
}
|
||||
|
||||
public static ArrayList<Produkt> umwandlung (ArrayList<Produkt> liste) throws FileNotFoundException {
|
||||
public 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(",");
|
||||
|
|
@ -68,9 +68,8 @@ public class OnlineShop {
|
|||
public String[] warenkorbToArray(){
|
||||
|
||||
String[] warenkorbZeilen = new String[warenkorb.menge.size()];
|
||||
double[] bruttopreis = warenkorb.bruttoPreisBerechnen();
|
||||
for (int i = 0; i < warenkorb.menge.size(); i++){
|
||||
warenkorbZeilen[i] = String.valueOf(warenkorb.menge.get(i) + " Stück | " + lager.get(i).getName() + " | " + (bruttopreis[i] * warenkorb.menge.get(i)) + "€");
|
||||
warenkorbZeilen[i] = String.valueOf(warenkorb.menge.get(i) + " Stück | " + lager.get(i).getName() + " | " + (lager.get(i).getBruttoPreis() * warenkorb.menge.get(i)) + "€");
|
||||
}
|
||||
return warenkorbZeilen;
|
||||
|
||||
|
|
@ -96,10 +95,9 @@ public class OnlineShop {
|
|||
bestellung.versandkosten = versandkostenUndAnteile[0];
|
||||
bestellung.anteil7 = versandkostenUndAnteile[1];
|
||||
bestellung.anteil19 = versandkostenUndAnteile[2];
|
||||
double[] bruttopreis = warenkorb.bruttoPreisBerechnen();
|
||||
double gesamtpreis = 0;
|
||||
for (int i = 0; i <bruttopreis.length; i++) {
|
||||
gesamtpreis += bruttopreis[i] * warenkorb.menge.get(i);
|
||||
for (int i = 0; i <warenkorb.menge.size(); i++) {
|
||||
gesamtpreis += lager.get(i).getBruttoPreis() * warenkorb.menge.get(i);
|
||||
}
|
||||
bestellung.gesamtPreis = versandkostenUndAnteile[0] + gesamtpreis;
|
||||
|
||||
|
|
|
|||
|
|
@ -7,9 +7,10 @@ public class Produkt {
|
|||
double preis;
|
||||
int mwSteuer;
|
||||
int lagerbestand;
|
||||
double bruttoPreis;
|
||||
|
||||
|
||||
public 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;
|
||||
|
|
@ -40,7 +41,13 @@ public class Produkt {
|
|||
return lagerbestand;
|
||||
}
|
||||
|
||||
public double getBruttoPreis() {
|
||||
double bruttopreis = (preis * mwSteuer) / 100.0 + 1;
|
||||
bruttopreis = (int) bruttopreis * 100 / 100.0;
|
||||
return bruttopreis;}
|
||||
|
||||
public String toString(){
|
||||
return this.produktNr + ", " + this.name + ", " + this.gewicht + ", " + this.preis + ", " + this.mwSteuer + ", " + this.lagerbestand;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,14 +14,6 @@ public class Warenkorb {
|
|||
this.produkte = produkte;
|
||||
}
|
||||
|
||||
public double[] bruttoPreisBerechnen() {
|
||||
double[] bruttopreis = new double[produkte.size()];
|
||||
for (int i = 0; i < produkte.size(); i++) {
|
||||
bruttopreis[i] = produkte.get(i).getPreis() * (produkte.get(i).getMwSteuer() / 100.0 + 1);
|
||||
bruttopreis[i] = (int) (bruttopreis[i]*100) / 100.0;
|
||||
}
|
||||
return bruttopreis;
|
||||
}
|
||||
|
||||
public double[] versandkostenBerechnen(){
|
||||
double gesamtGewicht = 0;
|
||||
|
|
|
|||
Loading…
Reference in New Issue