diff --git a/src/main/java/Model/Purchase.java b/src/main/java/Model/Purchase.java index 33c41e5..d367a7b 100644 --- a/src/main/java/Model/Purchase.java +++ b/src/main/java/Model/Purchase.java @@ -1,32 +1,36 @@ package Model; + import java.math.BigDecimal; +/** + * Purchase class whenever the player makes a purchase. + */ public class Purchase extends Transaction { - public Purchase(Share share, int week) { - super(share, week, new PurchaseCalculator(share)); - } + public Purchase(Share share, int week) { + super(share, week, new PurchaseCalculator(share)); + } - @Override - public void commit(Player player) { - if (player == null) { - throw new IllegalArgumentException("Player cannot be null"); - } - if (isCommitted()) { - throw new IllegalStateException("Purchase has already been committed"); - } + @Override + public void commit(Player player) { + if (player == null) { + throw new IllegalArgumentException("Player cannot be null"); + } + if (isCommitted()) { + throw new IllegalStateException("Purchase has already been committed"); + } - BigDecimal price = this.getCalculator().calculateTotal(); + BigDecimal price = this.getCalculator().calculateTotal(); - if (player.getMoney().compareTo(price) < 0) { - throw new IllegalStateException( - "Insufficient funds: required " + price + ", available " + player.getMoney() - ); - } + if (player.getMoney().compareTo(price) < 0) { + throw new IllegalStateException( + "Insufficient funds: required " + price + ", available " + player.getMoney() + ); + } - player.withdrawMoney(price); - player.getPortfolio().addShare(this.getShare()); - player.getTransactionArchive().add(this); + player.withdrawMoney(price); + player.getPortfolio().addShare(this.getShare()); + player.getTransactionArchive().add(this); - this.committed = true; - } + this.committed = true; + } }