diff --git a/src/main/java/Model/Player.java b/src/main/java/Model/Player.java index e7a1e31..cf3d8a3 100644 --- a/src/main/java/Model/Player.java +++ b/src/main/java/Model/Player.java @@ -9,6 +9,16 @@ public class Player { private TransactionArchive transactionArchive; public Player(String name, BigDecimal startingMoney) { + if (name == null || name.isBlank()) { + throw new IllegalArgumentException("Player name cannot be null or blank"); + } + if (startingMoney == null) { + throw new IllegalArgumentException("Starting money cannot be null"); + } + if (startingMoney.compareTo(BigDecimal.ZERO) < 0) { + throw new IllegalArgumentException("Starting money cannot be negative"); + } + this.name = name; this.startingMoney = startingMoney; this.money = startingMoney; @@ -25,10 +35,22 @@ public BigDecimal getMoney() { } public void addMoney(BigDecimal amount) { + if (amount == null) { + throw new IllegalArgumentException("Amount cannot be null"); + } + if (amount.compareTo(BigDecimal.ZERO) < 0) { + throw new IllegalArgumentException("Amount to add cannot be negative"); + } this.money = this.money.add(amount); } public void withdrawMoney(BigDecimal amount) { + if (amount == null) { + throw new IllegalArgumentException("Amount cannot be null"); + } + if (amount.compareTo(BigDecimal.ZERO) < 0) { + throw new IllegalArgumentException("Amount to withdraw cannot be negative"); + } this.money = this.money.subtract(amount); }