-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Solveig Natvig
committed
Mar 22, 2026
1 parent
95653ae
commit ba7303a
Showing
1 changed file
with
21 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |