Skip to content

Commit

Permalink
Finishing Purchase methods and constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
martin committed Mar 5, 2026
1 parent ec4cf02 commit 3ceaf8a
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/main/java/temppackage/Purchase.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
package temppackage;

import temppackage.calculators.PurchaseCalculator;

public class Purchase extends Transaction {

public Purchase(Share share, int week) {}
public Purchase(Share share, int week) {
super(share, week, new PurchaseCalculator(share));
}

@Override
public void commit(Player player) {
// TODO Auto-generated method stub
super.commit(player);
if (isCommitted()) {
throw new IllegalStateException("Already committed");
}

if (player.getMoney().compareTo(getCalculator().calculateTotal()) < 0) {
throw new IllegalStateException("Not enought money");
}
player.withdrawMoney(getCalculator().calculateTotal());
player.getPortfolio().addShare(getShare());
player.getTransactionArchive().add(this);
setCommitted(true);
}
}

0 comments on commit 3ceaf8a

Please sign in to comment.