From 790575d8fd2c2f3e2d38242b756cd525ca4581ac Mon Sep 17 00:00:00 2001 From: Elisabeth Berg Date: Sun, 24 May 2026 19:58:17 +0200 Subject: [PATCH] Update Share class with exceptions --- src/main/java/Model/Share.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/Model/Share.java b/src/main/java/Model/Share.java index dee79dd..92d6101 100644 --- a/src/main/java/Model/Share.java +++ b/src/main/java/Model/Share.java @@ -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;