Skip to content

Commit

Permalink
Feat: Made it possible to sell max stocks
Browse files Browse the repository at this point in the history
If attempting to sell more than currently held, the system simply sells every share
  • Loading branch information
tommyah committed May 15, 2026
1 parent cf09d0f commit f4ed619
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public Transaction sell(final Share share, final Player player)
*
* @throws IllegalArgumentException if any parameter is null, or if player does not have enough shares.
* */
public List<Transaction> sell(final BigDecimal amount, final String stockSymbol, final Player player)
public List<Transaction> sell(BigDecimal amount, final String stockSymbol, final Player player)
throws IllegalArgumentException {
if (amount == null || player == null || !Validator.NOT_EMPTY.isValid(stockSymbol)) {
throw new IllegalArgumentException("Invalid sell!");
Expand All @@ -221,7 +221,7 @@ public List<Transaction> sell(final BigDecimal amount, final String stockSymbol,
BigDecimal totalOwned = player.getPortfolio().getTotalSharesBySymbol(stockSymbol);

if (amount.compareTo(totalOwned) > 0) {
throw new IllegalArgumentException("Not enough shares!");
amount = totalOwned;
}
ArrayList<Transaction> transactions = new ArrayList<>();
BigDecimal remainingToSell = amount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ protected void initLayout() {
HBox header = new HBox(20);
header.setAlignment(Pos.CENTER_LEFT);


// Stock Identity (The gray pill)
VBox stockIdentity = new VBox(5);
selectedStockLabel = new Label("APL");
Expand Down Expand Up @@ -182,6 +183,10 @@ protected void initLayout() {
grid.add(qtySection, 0, 0, 6,1);
grid.add(tradeBtns, 0, 1, 6, 1);

HBox.setHgrow(stockIdentity, Priority.ALWAYS);
HBox.setHgrow(priceStats, Priority.ALWAYS);
HBox.setHgrow(grid, Priority.ALWAYS);

header.getChildren().addAll(stockIdentity, priceStats, grid);

Region spacer = new Region();
Expand Down

0 comments on commit f4ed619

Please sign in to comment.