-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Solveig Natvig
committed
Feb 26, 2026
1 parent
cca567e
commit e6e8a10
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import java.math.BigDecimal; | ||
| import java.util.Formatter.BigDecimalLayoutForm; | ||
|
|
||
| public class SaleCalculator { | ||
| private BigDecimal purchasePrice; | ||
| private BigDecimal salesPrice; | ||
| private BigDecimal quantity; | ||
|
|
||
| public SaleCalculator(Share share) { | ||
| this.purchasePrice = share.getPurchasePrice(); | ||
| this.salesPrice = salesPrice; // Ask about this one... | ||
| this.quantity = share.getQuantity(); | ||
| } | ||
|
|
||
| public BigDecimal calculateGross() { | ||
| return this.salesPrice.multiply(this.quantity); | ||
| } | ||
|
|
||
| public BigDecimal calculateCommission() { | ||
| BigDecimal rate = new BigDecimal("0.01"); | ||
| return calculateGross().multiply(rate); | ||
| } | ||
|
|
||
| public BigDecimal calculateTax() { | ||
| BigDecimal sellingCost = this.purchasePrice.multiply(this.quantity); | ||
| BigDecimal profit = calculateGross().subtract(calculateCommission()).subtract(sellingCost); | ||
| BigDecimal rate = new BigDecimal("0.3"); | ||
| return profit.multiply(rate); | ||
| } | ||
|
|
||
| public BigDecimal calculateTotal() { | ||
| return calculateGross().subtract(calculateCommission()).subtract(calculateTax()); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| } |