Skip to content

Commit

Permalink
SaleClaculator methods
Browse files Browse the repository at this point in the history
  • Loading branch information
EspenTinius committed Feb 19, 2026
1 parent f20e90b commit b8a404e
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/SaleCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,33 @@ public SaleCalculator(Share share) {
this.salesPrice = share.getStock().getSalesPrice();
this.quantity = share.getQuantity();
}

@Override
public BigDecimal calculateGross() {
return salesPrice.multiply(quantity);
}

@Override
public BigDecimal calculateCommission() {
return calculateGross().multiply(COMMISSION_RATE);
}

@Override
public BigDecimal calculateTax() {
BigDecimal purchaseCost = purchasePrice.multiply(quantity);
BigDecimal profit = calculateGross()
.subtract(calculateCommission())
.subtract(purchaseCost);

return profit.signum() > 0
? profit.multiply(TAX_RATE)
: BigDecimal.ZERO;
}

@Override
public BigDecimal calculateTotal() {
return calculateGross()
.subtract(calculateCommission())
.subtract(calculateTax());
}
}

0 comments on commit b8a404e

Please sign in to comment.