Skip to content

Commit

Permalink
Changing call order, adding null checks
Browse files Browse the repository at this point in the history
  • Loading branch information
martin committed Mar 6, 2026
1 parent 2d2244d commit 60d3872
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/main/java/millions/Exchange.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,23 @@ public Exchange(String name, List<Stock> stockList) {
}
}

public void buy(Player player, Stock stock, BigDecimal quantity) {
public void buy(String symbol, Player player, BigDecimal quantity) {

Stock stock = this.stocks.get(symbol);
if (stock == null) {
throw new IllegalArgumentException("Stock not found");
}

Share shareToBuy = new Share(stock, quantity, stock.getSalesPrice());
Purchase purchase = new Purchase(shareToBuy, this.weekNumber);
purchase.commit(player);
}

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

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

0 comments on commit 60d3872

Please sign in to comment.