-
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.
Merge pull request #10 from IDATT2003-gruppe06/main
Filled out remaining functionality in SaleCalculator
- Loading branch information
Showing
1 changed file
with
24 additions
and
1 deletion.
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 |
|---|---|---|
| @@ -1,14 +1,37 @@ | ||
| package temppackage.calculators; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.math.RoundingMode; | ||
|
|
||
| import temppackage.Share; | ||
|
|
||
| public class SaleCalculator { | ||
| public class SaleCalculator implements TransactionCalculator{ | ||
| BigDecimal purchasePrice; | ||
| BigDecimal salesPrice; | ||
| BigDecimal quantity; | ||
| public SaleCalculator(Share share) { | ||
| super(); | ||
| this.purchasePrice = share.getPurchasePrice(); | ||
| } | ||
| @Override | ||
| public BigDecimal calculateGross() { | ||
| return salesPrice.multiply(quantity); | ||
| } | ||
|
|
||
| @Override | ||
| public BigDecimal calculateComission() { | ||
| return this.calculateGross().divide(new BigDecimal("100"), RoundingMode.HALF_UP); | ||
| } | ||
|
|
||
| @Override | ||
| public BigDecimal calculateTax() { | ||
| BigDecimal purchaseCosts = this.purchasePrice.multiply(this.quantity); | ||
| BigDecimal earnings = this.calculateGross().subtract(this.calculateComission()).subtract(purchaseCosts); | ||
| return earnings.multiply(new BigDecimal("30")).divide(new BigDecimal("100"), RoundingMode.HALF_UP); | ||
| } | ||
|
|
||
| @Override | ||
| public BigDecimal calculateTotal() { | ||
| return this.calculateGross().subtract(this.calculateComission()).subtract(this.calculateTax()); | ||
| } | ||
| } |