diff --git a/src/main/java/millions/Player.java b/src/main/java/millions/Player.java index 747c8d0..6c01c2c 100644 --- a/src/main/java/millions/Player.java +++ b/src/main/java/millions/Player.java @@ -15,13 +15,27 @@ public Player(String name, BigDecimal startingMoney) { this.money = startingMoney; this.portfolio = new Portfolio(); this.transactionArchive = new TransactionArchive(); + + if (name == null || name.isBlank()) { + throw new IllegalArgumentException("Player name cannot be null or blank"); + } + + if (startingMoney == null || startingMoney.compareTo(BigDecimal.ZERO) < 0) { + throw new IllegalArgumentException("Starting money cannot be null or negative"); + } } public void addMoney(BigDecimal amount) { + if (amount == null || amount.compareTo(BigDecimal.ZERO) < 0) { + throw new IllegalArgumentException("Amount cannot be null or negative"); + } this.money = this.money.add(amount); } public void withdrawMoney(BigDecimal amount) { + if (amount == null || amount.compareTo(BigDecimal.ZERO) < 0) { + throw new IllegalArgumentException("Amount cannot be null or negative"); + } this.money = this.money.subtract(amount); }