#Big Feat
Cart.java: #Feat - Funktionen wie getThemBruttoPrices, getWeight,getShippingCost, getMwstRateOf7, getMwstRateOf19, getFinalTotal implementiert CartPosition.java: #Feat- getTotalBruttoPrice, getMwstAmount, getMwstRate, getProductWeight nach Cart.java angepasst #FIX: Bug ursache in product gefixed, fehlender brutto Attribute hinzugefügt plus getter Quellen wurden angepasstmain
parent
ff95a0b984
commit
aa059450e1
|
|
@ -44,3 +44,42 @@ public void updateProductQuantity(int prodID,int quantity) {
|
|||
|
||||
}
|
||||
|
||||
Gemini Prompt: für ShippingCost
|
||||
Für die Bestellung soll ein Brutto-Gesamtpreis aus den Kosten der Produkte sowie den Versandkosten berechnet werden.
|
||||
Die enthaltene Mehrwertsteuer (korrekt eigentlich Umsatzsteuer) soll ebenfalls ausgewiesen werden.
|
||||
Die Brutto-Versandkosten betragen bis (inkl.) 100 g 3,95 Euro bis 1 kg 4,95 Euro, bis 5 kg 5,95 Euro und darüber pauschal 19,95 Euro.
|
||||
Ab einem Warenwert von 500 Euro (brutto) ist die Lieferung versandkostenfrei.
|
||||
Wie bestimme ich die formel und bau das in meinen Java Online Text Shop mit ein, ich würde ungern blind alles copy pasten
|
||||
|
||||
Gemini Prompt: für Shipping Cost
|
||||
|
||||
Etwas kompliziert ist die
|
||||
MwSt.-Berechnung für die Versandkosten, hier gilt, dass die MwSt. sich
|
||||
nach den Versandkosten des Produkts bestimmt: Angenommen wir bestellen
|
||||
nur eine Flasche Riesling, wären das Versandkosten von 5,95 brutto. Da
|
||||
der Riesling einem MwSt.-Satz von 19% unterliegt, errechnet sich der
|
||||
Nettopreis auf die Versandkosten aus 5,95 / 1,19 = 5 Euro, womit die
|
||||
MwSt. 19 % beträgt.
|
||||
Doch damit noch nicht genug, wenn
|
||||
eine Lieferung nun bspw. Kosten von 100 Euro zu 7% MwSt. und 200 Euro zu
|
||||
19% MwSt. enthält, muss die MwSt. der 19,95 Euro Versandkosten auch
|
||||
anteilig nach dem Warenwert verteilt werden. Also 1/3 = 6,65 entfallen
|
||||
auf 7% (Nettopreis VK: 6,65 / 1,07), 2/3 = 13,30 auf 19% (Nettopreis VK:
|
||||
13,30 / 1,19).
|
||||
|
||||
erkläre mir wie ich das coden würde in java
|
||||
|
||||
Idee aus:
|
||||
How to Create a Shipping Cost Calculator in Java - Stackoverflow
|
||||
https://stackoverflow.com/questions/9013289/how-to-create-a-shipping-cost-calculator-in-java
|
||||
|
||||
|
||||
Test Idee:
|
||||
https://medium.com/@kingsleynwafor54/how-to-create-a-shopping-cart-api-using-java-with-unit-testing-ef51991e7cc
|
||||
|
||||
How to design the classes for a simple shopping cart example using Strategy Design Patterns
|
||||
https://softwareengineering.stackexchange.com/questions/347505/how-to-design-the-classes-for-a-simple-shopping-cart-example-using-strategy-desi
|
||||
|
||||
Shopping Cart Java Application (addToCart)
|
||||
https://stackoverflow.com/questions/18473130/shopping-cart-java-application-addtocart
|
||||
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public void removeProduct(int productID){
|
|||
positions.remove(gettinYETTED);
|
||||
}
|
||||
}
|
||||
|
||||
//Price of all pos without them taxes :p
|
||||
public double getTotalPrice() {
|
||||
double sum = 0;
|
||||
for(CartPosition pos : positions){
|
||||
|
|
@ -80,8 +80,85 @@ public void removeProduct(int productID){
|
|||
public List<CartPosition> getPositions() {
|
||||
return positions;
|
||||
}
|
||||
//wäre das autocomplete?
|
||||
//wäre das autocomplete? ---> video
|
||||
public void clear(){
|
||||
positions.clear();
|
||||
}
|
||||
//Brutto aller pos mit mwst
|
||||
public double getThemBruttoPrices() {
|
||||
double sum = 0;
|
||||
for (CartPosition pos : positions) {
|
||||
sum += pos.getTotalPrice();
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
public double getWeight(){
|
||||
double weight = 0;
|
||||
for(CartPosition pos : positions){
|
||||
weight += pos.getProductWeight();
|
||||
}
|
||||
return weight;
|
||||
}
|
||||
|
||||
public double getShippingCost(){
|
||||
double value = getThemBruttoPrices();
|
||||
if(value >= 500) return 0.0;
|
||||
double weight = getWeight();
|
||||
if(weight <= 0.1) return 3.95;
|
||||
if(weight <= 1.0) return 4.95;
|
||||
if(weight <= 5.0) return 5.95;
|
||||
return 19.95;
|
||||
}
|
||||
public double getMwstRateOf7(){
|
||||
double sum = 0;
|
||||
for(CartPosition pos : positions){
|
||||
if(pos.getMwstRate() == 7);
|
||||
sum += pos.getMwstAmount();
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
public double getMwstRateOf19(){
|
||||
double sum = 0;
|
||||
for(CartPosition pos : positions){
|
||||
if(pos.getMwstRate() == 19);
|
||||
sum += pos.getMwstAmount();
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
//Formel und prinzip nach KI-Prompt
|
||||
public double getFinalTotal(){
|
||||
double total7 = 0;
|
||||
double total19 = 0;
|
||||
for(CartPosition pos : positions){
|
||||
if(pos.getMwstRate() == 7){
|
||||
total7 += pos.getTotalBruttoPrice();
|
||||
|
||||
}else {
|
||||
total19 += pos.getTotalBruttoPrice();
|
||||
}
|
||||
}
|
||||
double totalBrutto = total7 + total19;
|
||||
double shipbrutto = getShippingCost();
|
||||
if(shipbrutto > 0){
|
||||
if(totalBrutto > 0){
|
||||
//Verhältnis und wenn Waren mit unterschiedlichen mwst im warenkorb sind
|
||||
double ratio7 = total7 / totalBrutto;
|
||||
double ratio19 = total19 / totalBrutto;
|
||||
|
||||
double shippingBy7 = totalBrutto * ratio7;
|
||||
double shippingBy19 = totalBrutto * ratio19;
|
||||
// Hier wird nur der Gesamtbetrag berechnet, nicht die MwSt-Aufteilung
|
||||
// Die anteiligen Versandkosten werden einfach addiert
|
||||
return totalBrutto + shippingBy7 + shippingBy19;
|
||||
}
|
||||
}
|
||||
return totalBrutto;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,17 @@ public class CartPosition {
|
|||
public double getTotalPrice(){
|
||||
return product.getNetPrice() * quantity;
|
||||
}
|
||||
//Habe Brutto getter vergessen
|
||||
public double getTotalBruttoPrice(){
|
||||
return product.getNetPrice() * quantity;
|
||||
}
|
||||
public double getMwstAmount() {
|
||||
return getTotalBruttoPrice() - getTotalPrice();
|
||||
}
|
||||
public double getMwstRate(){
|
||||
return product.getMwst();
|
||||
}
|
||||
|
||||
public Product getProduct(){
|
||||
return product;
|
||||
}
|
||||
|
|
@ -27,6 +38,10 @@ public class CartPosition {
|
|||
public void setQuantity(int quantity){
|
||||
this.quantity = quantity;
|
||||
}
|
||||
public double getProductWeight(){
|
||||
return product.getTransportWeight();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ public class Product {
|
|||
private String name;
|
||||
private double transportWeight;
|
||||
private double netPrice;
|
||||
private double bruttoPrice;
|
||||
private double mwst; // <----- Maybe final setzen
|
||||
private int stock;
|
||||
|
||||
|
|
@ -53,6 +54,9 @@ public class Product {
|
|||
public double getNetPrice() {
|
||||
return netPrice;
|
||||
}
|
||||
public double getBruttoPrice() {
|
||||
return bruttoPrice;
|
||||
}
|
||||
|
||||
public double getMwst() {
|
||||
return mwst;
|
||||
|
|
|
|||
Loading…
Reference in New Issue