From 5ee6dff6b434ef63646f76cfe6a79db6d74f86d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Einar=20Sk=C3=B8ien?= Date: Tue, 12 May 2026 14:27:51 +0200 Subject: [PATCH] implement portfolio in the BankApp --- .../AppControllers/BankAppController.java | 5 ++- .../idi/idatt2003/gruppe42/Model/Stock.java | 2 +- .../idatt2003/gruppe42/View/Apps/BankApp.java | 38 ++++++++++++++++++- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/AppControllers/BankAppController.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/AppControllers/BankAppController.java index 979d60d..22b49eb 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/AppControllers/BankAppController.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/AppControllers/BankAppController.java @@ -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()); } } diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Stock.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Stock.java index 5b9980b..194c26c 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Stock.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Stock.java @@ -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); } diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Apps/BankApp.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Apps/BankApp.java index 3c69933..9035e21 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Apps/BankApp.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Apps/BankApp.java @@ -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 portfolioList; private Label netWorthLabel = new Label("Net Worth: "); private Label unInvestedMoneyLabel = new Label("Cash: "); private Label investedMoneyLabel = new Label("Stock: "); @@ -20,6 +27,7 @@ public class BankApp extends Popup { */ public BankApp(){ super(400, 300, 120, 120, App.BANK); + portfolioList = new ListView<>(); updateContent(); } @@ -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() { + @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) { @@ -43,6 +75,10 @@ public void updateStatus(double netWorth, double unInvestedMoney, double investe updateContent(); }); } + + public ListView getPortfolioList() { + return portfolioList; + } }