From 15766628b8584540a1dc1593314600b8a3699198 Mon Sep 17 00:00:00 2001 From: EspenTinius Date: Fri, 20 Feb 2026 00:05:08 +0100 Subject: [PATCH 1/2] player class This will not work until other classes have been merged --- .../ntnu/idi/idatt2003/g40/mappe/Player.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Player.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Player.java index e69de29..da0811c 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Player.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Player.java @@ -0,0 +1,45 @@ +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; + + public Player(String name, BigDecimal startingMoney) { + this.name = name; + this.startingMoney = startingMoney; + this.money = this.startingMoney; + this.portfolio = new Portfolio(); + this.transactionArchive = new TransactionArchive(); + } + + public String getName() { + return name; + } + + public BigDecimal getMoney() { + return money; + } + + public void addMoney(BigDecimal amount) { + money = money.add(amount); + } + + public void withdrawMoney(BigDecimal amount) { + money = money.subtract(amount); + } + + public Portfolio getPortfolio() { + return portfolio; + } + + public TransactionArchive getTransactionArchive() { + return transactionArchive; + } +} \ No newline at end of file From 4077306b78b0f0bb4cc96622aa3e5625d73fd4d9 Mon Sep 17 00:00:00 2001 From: EspenTinius Date: Fri, 20 Feb 2026 00:08:38 +0100 Subject: [PATCH 2/2] Player class javadoc --- .../ntnu/idi/idatt2003/g40/mappe/Player.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Player.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Player.java index da0811c..0114bbf 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Player.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Player.java @@ -11,6 +11,12 @@ public class Player { 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; @@ -19,26 +25,56 @@ public Player(String name, BigDecimal startingMoney) { 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; }