Skip to content

implement portfolio in the BankApp #89

Merged
merged 1 commit into from
May 12, 2026
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ public BankAppController(BankApp bankApp, Player player) {
this.player = player;
this.bankApp = bankApp;
}

@Override
public void nextTick() {
System.out.println("[DEBUG] BankAppController.nextTick() - Updating Player Status");
bankApp.updateStatus(
player.getNetWorth().doubleValue(),
player.getMoney().doubleValue(),
player.getPortfolio().getNetWorth().doubleValue(),
0 // TODO: calculate growth
);
System.out.println("[DEBUG] BankAppController.nextTick() - Updating Player Status");

bankApp.getPortfolioList().getItems().setAll(player.getPortfolio().getShares());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public BigDecimal getLatestPriceChange() {

public void updatePrice() {
BigDecimal oldPrice = getSalesPrice();
BigDecimal newPrice = oldPrice.subtract(new BigDecimal("0"));
BigDecimal newPrice = oldPrice.add(new BigDecimal("1"));
newPrice = newPrice.max(BigDecimal.ZERO);
prices.add(newPrice);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package edu.ntnu.idi.idatt2003.gruppe42.View.Apps;

import edu.ntnu.idi.idatt2003.gruppe42.Model.App;
import edu.ntnu.idi.idatt2003.gruppe42.Model.Share;
import edu.ntnu.idi.idatt2003.gruppe42.Model.Stock;
import edu.ntnu.idi.idatt2003.gruppe42.View.Popup;
import javafx.application.Platform;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;

/**
* A popup for the Bank app.
*/
public class BankApp extends Popup {
private ListView<Share> portfolioList;
private Label netWorthLabel = new Label("Net Worth: ");
private Label unInvestedMoneyLabel = new Label("Cash: ");
private Label investedMoneyLabel = new Label("Stock: ");
Expand All @@ -20,6 +27,7 @@ public class BankApp extends Popup {
*/
public BankApp(){
super(400, 300, 120, 120, App.BANK);
portfolioList = new ListView<>();
updateContent();
}

Expand All @@ -31,7 +39,31 @@ private void updateContent(){
statusPane.add(investedMoneyLabel, 1, 1);
statusPane.add(growthPercentageLabel, 1, 0);

content.getChildren().setAll(statusPane);
portfolioList.setCellFactory(
lv ->
new ListCell<Share>() {
@Override
protected void updateItem(Share share, boolean empty) {
super.updateItem(share, empty);
if (empty || share == null) {
setGraphic(null);
} else {
GridPane sharePane = new GridPane();
sharePane.add(new Label(share.getStock().getCompany()), 0, 0);
sharePane.add(new Label("Purchase"), 1, 0);
sharePane.add(new Label(share.getStock().getSymbol()), 0, 1);
sharePane.add(new Label(share.getPurchasePrice().toString()), 1, 1);
sharePane.add(new Label("Quantity"), 0, 2);
sharePane.add(new Label("Sale"), 1, 2);
sharePane.add(new Label(share.getQuantity().toString()), 0, 3);
sharePane.add(new Label(share.getStock().getSalesPrice().toString()), 1, 3);
sharePane.setAlignment(Pos.CENTER_LEFT);
setGraphic(sharePane);
}
}
});

content.getChildren().setAll(statusPane, portfolioList);
}

public void updateStatus(double netWorth, double unInvestedMoney, double investedMoney, double growthPercentage) {
Expand All @@ -43,6 +75,10 @@ public void updateStatus(double netWorth, double unInvestedMoney, double investe
updateContent();
});
}

public ListView<Share> getPortfolioList() {
return portfolioList;
}
}