Die Bruttopreis berrechnung erfolgt jetzt in der Klasse Produkt.

main
igor.lewandowski 2025-12-28 14:38:55 +01:00
parent 8935b59916
commit 2a017af837
3 changed files with 13 additions and 16 deletions

View File

@ -14,7 +14,7 @@ public class OnlineShop {
umwandlung(lager); umwandlung(lager);
} }
public static ArrayList<String> readFile(String path) throws FileNotFoundException { public ArrayList<String> readFile(String path) throws FileNotFoundException {
ArrayList<String> lines = new ArrayList<>(); ArrayList<String> lines = new ArrayList<>();
Scanner sc = new Scanner(new File(path)); Scanner sc = new Scanner(new File(path));
@ -28,7 +28,7 @@ public class OnlineShop {
return lines; 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"); ArrayList<String> resource = readFile("resources\\produkte.csv");
for (int i = 1; i < resource.size(); i++) { for (int i = 1; i < resource.size(); i++) {
String[] teile = resource.get(i).split(","); String[] teile = resource.get(i).split(",");
@ -68,9 +68,8 @@ public class OnlineShop {
public String[] warenkorbToArray(){ public String[] warenkorbToArray(){
String[] warenkorbZeilen = new String[warenkorb.menge.size()]; String[] warenkorbZeilen = new String[warenkorb.menge.size()];
double[] bruttopreis = warenkorb.bruttoPreisBerechnen();
for (int i = 0; i < warenkorb.menge.size(); i++){ 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; return warenkorbZeilen;
@ -96,10 +95,9 @@ public class OnlineShop {
bestellung.versandkosten = versandkostenUndAnteile[0]; bestellung.versandkosten = versandkostenUndAnteile[0];
bestellung.anteil7 = versandkostenUndAnteile[1]; bestellung.anteil7 = versandkostenUndAnteile[1];
bestellung.anteil19 = versandkostenUndAnteile[2]; bestellung.anteil19 = versandkostenUndAnteile[2];
double[] bruttopreis = warenkorb.bruttoPreisBerechnen();
double gesamtpreis = 0; double gesamtpreis = 0;
for (int i = 0; i <bruttopreis.length; i++) { for (int i = 0; i <warenkorb.menge.size(); i++) {
gesamtpreis += bruttopreis[i] * warenkorb.menge.get(i); gesamtpreis += lager.get(i).getBruttoPreis() * warenkorb.menge.get(i);
} }
bestellung.gesamtPreis = versandkostenUndAnteile[0] + gesamtpreis; bestellung.gesamtPreis = versandkostenUndAnteile[0] + gesamtpreis;

View File

@ -7,9 +7,10 @@ public class Produkt {
double preis; double preis;
int mwSteuer; int mwSteuer;
int lagerbestand; 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.produktNr = produktNr;
this.name = name; this.name = name;
this.gewicht = gewicht; this.gewicht = gewicht;
@ -40,7 +41,13 @@ public class Produkt {
return lagerbestand; return lagerbestand;
} }
public double getBruttoPreis() {
double bruttopreis = (preis * mwSteuer) / 100.0 + 1;
bruttopreis = (int) bruttopreis * 100 / 100.0;
return bruttopreis;}
public String toString(){ public String toString(){
return this.produktNr + ", " + this.name + ", " + this.gewicht + ", " + this.preis + ", " + this.mwSteuer + ", " + this.lagerbestand; return this.produktNr + ", " + this.name + ", " + this.gewicht + ", " + this.preis + ", " + this.mwSteuer + ", " + this.lagerbestand;
} }
} }

View File

@ -14,14 +14,6 @@ public class Warenkorb {
this.produkte = produkte; 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(){ public double[] versandkostenBerechnen(){
double gesamtGewicht = 0; double gesamtGewicht = 0;