Skip to content

Commit

Permalink
Added Portfolio class
Browse files Browse the repository at this point in the history
  • Loading branch information
elisab3 committed Feb 24, 2026
1 parent ce3580d commit 99d7fc9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/main/java/Portfolio.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import java.util.ArrayList;
import java.util.List;

public class Portfolio {

private final List<Share> shares;

public Portfolio() {
this.shares = new ArrayList<>();
}

public boolean addShare(Share share) {
return shares.add(share);
}

public boolean removeShare(Share share) {
return shares.remove(share);
}

public List<Share> getShares() {
return new ArrayList<>(shares);
}

public List<Share> getShares(String symbol) {
List<Share> result = new ArrayList<>();
for (Share share : shares) {
if (share.getStock().getSymbol().equals(symbol)) {
result.add(share);
}
}
return result;
}

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

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

0 comments on commit 99d7fc9

Please sign in to comment.