-
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.
Merge pull request #47 from Team-40-IDATT2003/33-player-class
enhancement/33-player-class
- Loading branch information
Showing
1 changed file
with
81 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,81 @@ | ||
| package edu.ntnu.idi.idatt2003.g40.mappe; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.util.Objects; | ||
|
|
||
| public class Player { | ||
|
|
||
| private final String name; | ||
| private final BigDecimal startingMoney; | ||
| private BigDecimal money; | ||
| private final Portfolio portfolio; | ||
| private final TransactionArchive transactionArchive; | ||
|
|
||
| /** | ||
| * Creates a new player with a given name and starting capital. | ||
| * | ||
| * @param name the name of the player | ||
| * @param startingMoney the starting amount of money | ||
| */ | ||
| public Player(String name, BigDecimal startingMoney) { | ||
| this.name = name; | ||
| this.startingMoney = startingMoney; | ||
| this.money = this.startingMoney; | ||
| this.portfolio = new Portfolio(); | ||
| this.transactionArchive = new TransactionArchive(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the name of the player. | ||
| * | ||
| * @return the player's name | ||
| */ | ||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the players current balance. | ||
| * | ||
| * @return the current amount of money | ||
| */ | ||
| public BigDecimal getMoney() { | ||
| return money; | ||
| } | ||
|
|
||
| /** | ||
| * Adds money to the players balance. | ||
| * | ||
| * @param amount the amount to add | ||
| */ | ||
| public void addMoney(BigDecimal amount) { | ||
| money = money.add(amount); | ||
| } | ||
|
|
||
| /** | ||
| * Withdraws money from the players balance. | ||
| * | ||
| * @param amount the amount to withdraw | ||
| */ | ||
| public void withdrawMoney(BigDecimal amount) { | ||
| money = money.subtract(amount); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the players portfolio. | ||
| * | ||
| * @return the portfolio | ||
| */ | ||
| public Portfolio getPortfolio() { | ||
| return portfolio; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the players transaction archive. | ||
| * | ||
| * @return the transaction archive | ||
| */ | ||
| public TransactionArchive getTransactionArchive() { | ||
| return transactionArchive; | ||
| } | ||
| } |