Skip to content

Commit

Permalink
Add commit method
Browse files Browse the repository at this point in the history
  • Loading branch information
Solveig Natvig committed Mar 22, 2026
1 parent 95653ae commit ba7303a
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main/java/Sale.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import java.math.BigDecimal;

public class Sale extends Transaction {
public Sale(Share share, int week) {
super(share, week, new SaleCalculator(share));
}

public void commit(Player player) {
BigDecimal price = getCalculator().calculateTotal();

if (isCommitted() || !player.getPortfolio().contains(this.getShare())) {
return;
}

player.addMoney(price);
player.getPortfolio().removeShare(this.getShare());
player.getTransactionArchive().add(this);

this.committed = true;
}
}

0 comments on commit ba7303a

Please sign in to comment.