Skip to content

Commit

Permalink
Added getNetWorth methods to player and portfolio
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikollai committed Apr 8, 2026
1 parent a6c0ce1 commit 0771753
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/millions/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public void withdrawMoney(BigDecimal amount) {
this.money = this.money.subtract(amount);
}

public BigDecimal getNetWorth() {
BigDecimal netWorth = this.money;
netWorth = netWorth.add(this.portfolio.getNetWorth());
return netWorth;
}

public String getName() {
return this.name;
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/millions/Portfolio.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package millions;

import millions.calculators.SaleCalculator;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -28,6 +31,14 @@ public List<Share> getShares(String symbol) {
.toList();
}

public BigDecimal getNetWorth() {
BigDecimal netWorth = new BigDecimal(0);
for (Share share : shares) {
netWorth = netWorth.add(new SaleCalculator(share).calculateTotal());
}
return netWorth;
}

public boolean contains(Share share) {
return this.shares.contains(share);
}
Expand Down

0 comments on commit 0771753

Please sign in to comment.