Skip to content

Commit

Permalink
Update Stock class with exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
elisab3 committed May 24, 2026
1 parent 790575d commit 30d025e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/main/java/Model/Stock.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ public class Stock {
private final List<BigDecimal> prices;

public Stock(String symbol, String company, BigDecimal salesPrice) {
if (symbol == null || symbol.isBlank()) {
throw new IllegalArgumentException("Symbol cannot be null or blank");
}
if (company == null || company.isBlank()) {
throw new IllegalArgumentException("Company name cannot be null or blank");
}
if (salesPrice == null) {
throw new IllegalArgumentException("Initial sales price cannot be null");
}
if (salesPrice.compareTo(BigDecimal.ZERO) < 0) {
throw new IllegalArgumentException("Initial sales price cannot be negative");
}

this.symbol = symbol;
this.company = company;
this.prices = new ArrayList<>();
Expand All @@ -29,6 +42,12 @@ public BigDecimal getSalesPrice() {
}

public void addNewSalesPrice(BigDecimal price) {
if (price == null) {
throw new IllegalArgumentException("Price cannot be null");
}
if (price.compareTo(BigDecimal.ZERO) < 0) {
throw new IllegalArgumentException("Price cannot be negative");
}
prices.add(price);
}

Expand Down

0 comments on commit 30d025e

Please sign in to comment.