Skip to content

Commit

Permalink
Added getNetWorth() method to Portfolio class
Browse files Browse the repository at this point in the history
  • Loading branch information
elisab3 committed Mar 24, 2026
1 parent d2c472a commit 4a105f8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/java/Portfolio.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -34,5 +35,14 @@ public List<Share> getShares(String symbol) {
public boolean contains(Share share) {
return shares.contains(share);
}

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

}
Binary file modified target/classes/Portfolio.class
Binary file not shown.

0 comments on commit 4a105f8

Please sign in to comment.