Skip to content

Commit

Permalink
Merge pull request #29 from IDATT2003-gruppe06/4-create-getnetworth-m…
Browse files Browse the repository at this point in the history
…ethod-for-portfolio-class

Added getNetWorth methods to player and portfolio
  • Loading branch information
nolydvo authored Apr 8, 2026
2 parents a6c0ce1 + 0771753 commit ce0dc04
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 ce0dc04

Please sign in to comment.