-
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
Showing
1 changed file
with
44 additions
and
33 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 |
|---|---|---|
| @@ -1,44 +1,55 @@ | ||
| package Model; | ||
|
|
||
| import java.math.BigDecimal; | ||
|
|
||
| /** | ||
| * Share class. | ||
| */ | ||
| public class Share { | ||
|
|
||
| private final Stock stock; | ||
| private final BigDecimal quantity; | ||
| private final BigDecimal purchasePrice; | ||
|
|
||
| public Share(Stock stock, BigDecimal quantity, BigDecimal purchasePrice) { | ||
| if (stock == null) { | ||
| throw new IllegalArgumentException("Stock cannot be null"); | ||
| } | ||
| if (quantity == null) { | ||
| throw new IllegalArgumentException("Quantity cannot be null"); | ||
| } | ||
| if (quantity.compareTo(BigDecimal.ZERO) <= 0) { | ||
| throw new IllegalArgumentException("Quantity must be greater than zero"); | ||
| } | ||
| if (purchasePrice == null) { | ||
| throw new IllegalArgumentException("Purchase price cannot be null"); | ||
| } | ||
| if (purchasePrice.compareTo(BigDecimal.ZERO) < 0) { | ||
| throw new IllegalArgumentException("Purchase price cannot be negative"); | ||
| } | ||
|
|
||
| this.stock = stock; | ||
| this.quantity = quantity; | ||
| this.purchasePrice = purchasePrice; | ||
| } | ||
| private final Stock stock; | ||
| private final BigDecimal quantity; | ||
| private final BigDecimal purchasePrice; | ||
|
|
||
| public Stock getStock() { | ||
| return stock; | ||
| /** | ||
| * Share method that has stock, quantity and purchaseprice. | ||
| * | ||
| * @param stock stock name | ||
| * @param quantity quantity of stock | ||
| * @param purchasePrice price of stock | ||
| */ | ||
| public Share(Stock stock, BigDecimal quantity, BigDecimal purchasePrice) { | ||
| if (stock == null) { | ||
| throw new IllegalArgumentException("Stock cannot be null"); | ||
| } | ||
| if (quantity == null) { | ||
| throw new IllegalArgumentException("Quantity cannot be null"); | ||
| } | ||
| if (quantity.compareTo(BigDecimal.ZERO) <= 0) { | ||
| throw new IllegalArgumentException("Quantity must be greater than zero"); | ||
| } | ||
|
|
||
| public BigDecimal getQuantity() { | ||
| return quantity; | ||
| if (purchasePrice == null) { | ||
| throw new IllegalArgumentException("Purchase price cannot be null"); | ||
| } | ||
|
|
||
| public BigDecimal getPurchasePrice() { | ||
| return purchasePrice; | ||
| if (purchasePrice.compareTo(BigDecimal.ZERO) < 0) { | ||
| throw new IllegalArgumentException("Purchase price cannot be negative"); | ||
| } | ||
|
|
||
| this.stock = stock; | ||
| this.quantity = quantity; | ||
| this.purchasePrice = purchasePrice; | ||
| } | ||
|
|
||
| public Stock getStock() { | ||
| return stock; | ||
| } | ||
|
|
||
| public BigDecimal getQuantity() { | ||
| return quantity; | ||
| } | ||
|
|
||
| public BigDecimal getPurchasePrice() { | ||
| return purchasePrice; | ||
| } | ||
|
|
||
| } |