Issue 6 und korrektur des Bestellvorgangs

main
Laura Kalkbrenner 2026-01-09 00:09:15 +01:00
parent 53acfa0eab
commit e20ed20406
6 changed files with 46 additions and 28 deletions

View File

@ -2,58 +2,65 @@ package pack;
import java.util.ArrayList; import java.util.ArrayList;
public class Bestellungen { public class Bestellung {
String kundenName; String kundenName;
String Addresse; String Addresse;
Warenkorb wk; Warenkorb wk;
ArrayList<WarenkorbArtikel> warenkorb ; ArrayList<WarenkorbArtikel> warenkorb ;
double Bruttopreis=0; double Bruttopreis;
double versandkosten; double versandkosten;
boolean bestellungBestätigt; boolean bestellungBestätigt;
double gesamtPreis; double gesamtPreis;
double gesamtGewicht=0; double gesamtGewicht;
double mwstGesamt; // hab die Aufgabe nicht verstanden bzw nicht umsetzten können double mwstGesamt; // hab die Aufgabe nicht verstanden bzw nicht umsetzten können
public Bestellungen(String kundenName,String Addresse,ArrayList<WarenkorbArtikel> warenkorb) { public Bestellung(String kundenName,String Addresse,ArrayList<WarenkorbArtikel> warenkorb) {
this.kundenName=kundenName; this.kundenName=kundenName;
this.Addresse=Addresse; this.Addresse=Addresse;
this.warenkorb=warenkorb; this.warenkorb=warenkorb;
this.Bruttopreis=berechnegBruttoPreis(); this.Bruttopreis=berechnegBruttoPreis();
this.bestellungBestätigt = true; this.bestellungBestätigt = true;
this.gesamtGewicht=berechneGesamtGewicht();
this.versandkosten=versandkostenBerechnen(); this.versandkosten=versandkostenBerechnen();
this.gesamtPreis=Bruttopreis+versandkosten; this.gesamtPreis=Bruttopreis+versandkosten;
} }
public String toString(){ public String toString(){
return "Bestellung getätigt von"+ kundenName+" Lieferaddresse: "+Addresse+ " Preis: "+ Bruttopreis+ " zzgl. "+ return "Bestellung getätigt von "+ kundenName+" Lieferaddresse: "+Addresse+ " Preis: "+ Bruttopreis+"€"+ " zzgl. "+
versandkosten+ " Versandkosten"; versandkosten+ " Versandkosten, insgesamt "+gesamtPreis+"€";
} }
public double berechnegBruttoPreis(){ public double berechnegBruttoPreis(){
double summe =0.0;
for(int i=0;i<warenkorb.size();i++){ for(int i=0;i<warenkorb.size();i++){
Bruttopreis+= warenkorb.get(i).neuPreis; summe+= warenkorb.get(i).bruttopreis;
} }
return Bruttopreis; return summe;
} }
double berechneGesamtGewicht(){ double berechneGesamtGewicht(){
double gewicht = 0.0;
for(int i=0;i<warenkorb.size();i++){ for(int i=0;i<warenkorb.size();i++){
gesamtGewicht+= warenkorb.get(i).gesamtGewicht; gewicht+= warenkorb.get(i).gesamtGewicht;
}return gesamtGewicht; }return gewicht;
} }
public double versandkostenBerechnen(){ public double versandkostenBerechnen(){
if(berechnegBruttoPreis()>=500){ double brutto= berechnegBruttoPreis();
double gewicht= berechneGesamtGewicht();
if(brutto>=500){
return versandkosten=0.0; return versandkosten=0.0;
} }
if(100*berechneGesamtGewicht()<=100){ if(1000*gewicht<=100){
return versandkosten=3.95; return versandkosten=3.95;
} else if (berechneGesamtGewicht()+1000<=1000) { } else if (gewicht*1000<=1000) {
return 4.95; return 4.95;
}else if (berechneGesamtGewicht()+1000<=5000) { }else if (gewicht*1000<=5000) {
return 5.95; return 5.95;
}else }else
return 19.95; return 19.95;

View File

@ -119,11 +119,11 @@ public class OnlineShop {
return null; return null;
} }
public Bestellungen bestellVorgang(String Name, String Addresse){ public Bestellung bestellVorgang(String Name, String Addresse){
Bestellungen bestellung= new Bestellungen(Name, Addresse, Artikel ); ArrayList<WarenkorbArtikel> artikel = warenkorb.ÜbertrageArtikel();
ArrayList<WarenkorbArtikel> artikel = Bestellung bestellung= new Bestellung(Name, Addresse, artikel );
new ArrayList<>(warenkorb.ÜbertrageArtikel());
Artikel.clear(); //Mit KI (2) artikel.clear(); //Mit KI (2)
return bestellung; return bestellung;
} }

View File

@ -21,6 +21,7 @@ public class Produkt {
this.ID=ID; this.ID=ID;
this.mwstSatz=berechneMwst(); this.mwstSatz=berechneMwst();
this.bruttopreis=berechneBrutto(); this.bruttopreis=berechneBrutto();
} }
public String toString() { public String toString() {

View File

@ -14,6 +14,7 @@ public class Warenkorb {
} }
public Produkt welchesProdukt(int vltID) { public Produkt welchesProdukt(int vltID) {
for(Produkt p: produkte){ for(Produkt p: produkte){

View File

@ -5,23 +5,30 @@ public class WarenkorbArtikel {
int Menge; int Menge;
double neuPreis; double neuPreis;
double gesamtGewicht; double gesamtGewicht;
double bruttopreis;
public WarenkorbArtikel(Produkt produkt, int Menge) { public WarenkorbArtikel(Produkt produkt, int Menge) {
this.produkt = produkt; this.produkt = produkt;
this.Menge = Menge; this.Menge = Menge;
this.neuPreis=berechneGesamtPreis(); this.neuPreis=berechneGesamtPreis();
this.gesamtGewicht=berechneGesamtPreis(); this.gesamtGewicht=berechneGesamtGewicht();
this.bruttopreis=bruttoGesamtPreis();
}
public WarenkorbArtikel() {
} }
@Override @Override
public String toString() { public String toString() {
return "Produkt: " + produkt + ", Menge: " + Menge +", Brutto-Preis insgesamt:" +neuPreis +" davon Mwst: "+ produkt.mwstSatz*Menge; //Mit KI siehe (1) return "Produkt: " + produkt + ", Menge: " + Menge +", Bruttopreis:" + bruttoGesamtPreis()+"€ davon "+ produkt.mwstSatz*Menge +"€ Mwst , Nettopreis: "+ berechneGesamtPreis()+ "€ Gesamtgewicht: "+ berechneGesamtGewicht() +"kg"; //Mit KI siehe (1)
} }
public static double berechneGesamtPreis(){ public double berechneGesamtPreis(){
if(Menge!=0){ return
neuPreis= produkt.bruttopreis*Menge ;} neuPreis= produkt.preis*Menge ;
else
neuPreis=0; }
return neuPreis; public double bruttoGesamtPreis(){
double brutto= produkt.bruttopreis*Menge;
return brutto;
} }
public double berechneGesamtGewicht(){ public double berechneGesamtGewicht(){
if(Menge==0){ if(Menge==0){
@ -31,4 +38,5 @@ public class WarenkorbArtikel {
return gewicht; return gewicht;
} }
} }

View File

@ -135,7 +135,8 @@ public class ShopTUI {
String Name= sc.nextLine(); String Name= sc.nextLine();
IO.println("Addresse" ); IO.println("Addresse" );
String Adresse= sc.nextLine(); String Adresse= sc.nextLine();
Bestellungen best=shop.bestellVorgang(Name,Adresse); Bestellung best=shop.bestellVorgang(Name,Adresse);
IO.println(best); IO.println(best);
} }