Skip to content

Commit

Permalink
Update Share class with exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
elisab3 committed May 24, 2026
1 parent 588cd2d commit 790575d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main/java/Model/Share.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@ public class Share {
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;
Expand Down

0 comments on commit 790575d

Please sign in to comment.