Skip to content

Commit

Permalink
Finishing sale constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
martin committed Mar 5, 2026
1 parent 9964e4b commit 74507e4
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/main/java/temppackage/Sale.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
package temppackage;

import temppackage.calculators.SaleCalculator;

public class Sale extends Transaction {
public Sale(Share share, int week) {}

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

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

if (!player.getPortfolio().contains(getShare())) {
throw new IllegalStateException("Does not own the share");
}
player.addMoney(getCalculator().calculateTotal());
player.getPortfolio().removeShare(getShare());
player.getTransactionArchive().add(this);
setCommitted(true);
}
}

0 comments on commit 74507e4

Please sign in to comment.