-
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.
Finishing Purchase methods and constructor
- Loading branch information
martin
committed
Mar 5, 2026
1 parent
ec4cf02
commit 3ceaf8a
Showing
1 changed file
with
16 additions
and
3 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 |
|---|---|---|
| @@ -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); | ||
| } | ||
| } |