Skip to content

Commit

Permalink
adding null check and int quantity overloader
Browse files Browse the repository at this point in the history
  • Loading branch information
martin committed Mar 6, 2026
1 parent 2e2217b commit 2d2244d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/millions/Exchange.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public Exchange(String name, List<Stock> stockList) {
this.stocks = new HashMap<>();
this.weekNumber = 1;

if (name == null || name.isBlank()) {
throw new IllegalArgumentException("Exchange name cannot be null or blank");
}

// Populate the stocks map to get ticker -> stock
for (Stock stock : stockList) {
this.stocks.put(stock.getSymbol(), stock);
Expand All @@ -30,6 +34,10 @@ public void buy(Player player, Stock stock, BigDecimal quantity) {
purchase.commit(player);
}

public void buy(Player player, Stock stock, int quantity) {
this.buy(player, stock, BigDecimal.valueOf(quantity));
}

public void sell(Player player, Share share) {
Sale sale = new Sale(share, weekNumber);
sale.commit(player);
Expand Down

0 comments on commit 2d2244d

Please sign in to comment.