From 49ca49fc71af548f5267880f3ed48a363b0a61bd Mon Sep 17 00:00:00 2001 From: Roar Date: Mon, 25 May 2026 20:20:31 +0200 Subject: [PATCH 1/8] Updated Player Changed .addListener to .subscribe and made updateNetWorth() private. --- millions/src/main/java/no/ntnu/gruppe53/model/Player.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/millions/src/main/java/no/ntnu/gruppe53/model/Player.java b/millions/src/main/java/no/ntnu/gruppe53/model/Player.java index 7c2610d..21a9e9e 100644 --- a/millions/src/main/java/no/ntnu/gruppe53/model/Player.java +++ b/millions/src/main/java/no/ntnu/gruppe53/model/Player.java @@ -30,7 +30,7 @@ public class Player { /** * Creates a player with a given starting balance. - *

Adds a listener to the netWorth property to notify of changes in the player's net worth.

+ *

Subscribes to the netWorth property to notify of changes in the player's net worth.

* * @param name the player's name; must not be {@code null} or blank * @param startingMoney the initial monetary balance of the @@ -55,8 +55,7 @@ public Player(String name, BigDecimal startingMoney) { this.portfolio = new Portfolio(); this.transactionArchive = new TransactionArchive(); - portfolio.netWorthProperty().addListener( - (obs, oldVal, newVal) -> updateNetWorth()); + portfolio.netWorthProperty().subscribe(price -> updateNetWorth()); updateNetWorth(); } @@ -72,7 +71,7 @@ public ObjectProperty getNetWorthProperty() { /** * Mirrors the change in the player's net worth to the observable property. */ - public void updateNetWorth() { + private void updateNetWorth() { netWorthProperty.set(getNetWorth()); } From 01f29b1ca8920846b159a90d02cb968f83b382a8 Mon Sep 17 00:00:00 2001 From: Roar Date: Mon, 25 May 2026 20:20:56 +0200 Subject: [PATCH 2/8] Updated Portfolio Made updateNetWorth() private. --- millions/src/main/java/no/ntnu/gruppe53/model/Portfolio.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/millions/src/main/java/no/ntnu/gruppe53/model/Portfolio.java b/millions/src/main/java/no/ntnu/gruppe53/model/Portfolio.java index 1164f6b..6a3c5f9 100644 --- a/millions/src/main/java/no/ntnu/gruppe53/model/Portfolio.java +++ b/millions/src/main/java/no/ntnu/gruppe53/model/Portfolio.java @@ -159,7 +159,7 @@ public ObjectProperty netWorthProperty() { /** * Mirrors the portfolio's net worth to the observable. */ - public void updateNetWorth() { + private void updateNetWorth() { netWorthProperty.set(getNetWorth()); } } \ No newline at end of file From ec56ff638cc00cc1f943b45105c4f780dd7febf0 Mon Sep 17 00:00:00 2001 From: Roar Date: Mon, 25 May 2026 21:57:11 +0200 Subject: [PATCH 3/8] Updated SaleCalculator Added getProfitProperty() and a observable of the profit of a sale. --- .../main/java/no/ntnu/gruppe53/model/SaleCalculator.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/millions/src/main/java/no/ntnu/gruppe53/model/SaleCalculator.java b/millions/src/main/java/no/ntnu/gruppe53/model/SaleCalculator.java index e96015a..c6afe07 100644 --- a/millions/src/main/java/no/ntnu/gruppe53/model/SaleCalculator.java +++ b/millions/src/main/java/no/ntnu/gruppe53/model/SaleCalculator.java @@ -21,6 +21,7 @@ public class SaleCalculator implements TransactionCalculator { private final ObjectProperty commissionProperty = new SimpleObjectProperty<>(); private final ObjectProperty taxProperty = new SimpleObjectProperty<>(); private final ObjectProperty totalProperty = new SimpleObjectProperty<>(); + private final ObjectProperty profitProperty = new SimpleObjectProperty<>(); /** * Sets the quantity, purchase and sales price based on the given share. @@ -36,6 +37,7 @@ public SaleCalculator(Share share) { this.commissionProperty.set(calculateCommission()); this.taxProperty.set(calculateTax()); this.totalProperty.set(calculateTotal()); + this.profitProperty.set(calculateTotal().subtract(purchasePrice.multiply(quantity))); } /** @@ -135,4 +137,10 @@ public ObjectProperty getTaxProperty() { public ObjectProperty getTotalProperty() { return totalProperty; } + + /** + * Returns an observable of the calculated profit + * @return an observable of the calculated profit + */ + public ObjectProperty getProfitProperty() {return profitProperty;} } \ No newline at end of file From 02799c7c444f76ecfed0a8433590d4559be43259 Mon Sep 17 00:00:00 2001 From: Roar Date: Mon, 25 May 2026 21:58:18 +0200 Subject: [PATCH 4/8] Updated PortfolioView Added a label, textfield and subscriptipn related to the calculated profit of a sale. --- .../no/ntnu/gruppe53/view/PortfolioView.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/millions/src/main/java/no/ntnu/gruppe53/view/PortfolioView.java b/millions/src/main/java/no/ntnu/gruppe53/view/PortfolioView.java index 290d375..1d05348 100644 --- a/millions/src/main/java/no/ntnu/gruppe53/view/PortfolioView.java +++ b/millions/src/main/java/no/ntnu/gruppe53/view/PortfolioView.java @@ -55,6 +55,7 @@ public class PortfolioView extends BorderPane { private TextField commission; private TextField tax; private TextField total; + private TextField profit; //PortfolioListView private ListView portfolioListView; @@ -66,6 +67,7 @@ public class PortfolioView extends BorderPane { private Subscription commissionSubscription; private Subscription taxSubscription; private Subscription totalSubscription; + private Subscription profitSubscription; /** * Builds the view components and places them in the center pane. @@ -204,7 +206,13 @@ protected void updateItem(Share item, boolean empty) { total.setEditable(false); total.setMaxWidth(200); - totalBox.getChildren().addAll(totalLabel, total); + Label profitLabel = new Label(); + profitLabel.textProperty().bind(lm.bindString("portfolioProfit")); + profit = new TextField(); + profit.setEditable(false); + profit.setMaxWidth(200); + + totalBox.getChildren().addAll(totalLabel, total, profitLabel, profit); sellButton = new Button(); sellButton.textProperty().bind(lm.bindString("sellButton")); @@ -323,6 +331,13 @@ public void setSaleCalculator(SaleCalculator saleCalculator) { total.setText(""); } }); + profitSubscription = saleCalculator.getProfitProperty().subscribe(newVal -> { + if (newVal != null) { + profit.setText("$ " + newVal.setScale(2, RoundingMode.HALF_EVEN)); + } else { + profit.setText(""); + } + }); } From 7524fe829f28ad07bc5b8f66c8ebc9e33ef7876c Mon Sep 17 00:00:00 2001 From: Roar Date: Mon, 25 May 2026 21:59:07 +0200 Subject: [PATCH 5/8] Updated TransactionArchiveView Increased the information a string of transaction info gives the player. Now the player is more informed about what the transaction entailed. --- .../gruppe53/view/TransactionArchiveView.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/millions/src/main/java/no/ntnu/gruppe53/view/TransactionArchiveView.java b/millions/src/main/java/no/ntnu/gruppe53/view/TransactionArchiveView.java index fb5e11b..91e64b4 100644 --- a/millions/src/main/java/no/ntnu/gruppe53/view/TransactionArchiveView.java +++ b/millions/src/main/java/no/ntnu/gruppe53/view/TransactionArchiveView.java @@ -12,10 +12,7 @@ import java.math.RoundingMode; import javafx.util.Subscription; -import no.ntnu.gruppe53.model.Player; -import no.ntnu.gruppe53.model.Transaction; -import no.ntnu.gruppe53.model.Purchase; -import no.ntnu.gruppe53.model.Sale; +import no.ntnu.gruppe53.model.*; import no.ntnu.gruppe53.service.FormatBigDecimal; import no.ntnu.gruppe53.service.LanguageManager; @@ -96,17 +93,28 @@ protected void updateItem(Transaction item, boolean empty) { } else { Runnable updateTextAction = () -> { String typeStr; + BigDecimal price = BigDecimal.ZERO; + BigDecimal profit = BigDecimal.ZERO; // Changed to allow for more transaction types in the future if (item instanceof Purchase) { typeStr = lm.getString("historyTypePurchase"); - } else if (item instanceof Sale) { + price = item.getShare().getPurchasePrice(); + } else if (item instanceof Sale sale) { typeStr = lm.getString("historyTypeSale"); + price = item.getShare().getStock().getSalesPrice(); + if (sale.getCalculator() instanceof SaleCalculator saleCalc) { + profit = saleCalc.getProfitProperty().getValue(); + } } else { typeStr = "ERROR"; } BigDecimal quantity = item.getShare().getQuantity(); + BigDecimal gross = item.getCalculator().calculateGross(); + BigDecimal commission = item.getCalculator().calculateCommission(); + BigDecimal tax = item.getCalculator().calculateTax(); BigDecimal total = item.getCalculator().calculateTotal(); + String symbol = item.getShare().getStock().getSymbol(); String template = lm.getString("historyCellFormat"); @@ -115,8 +123,13 @@ protected void updateItem(Transaction item, boolean empty) { item.getWeek(), typeStr, symbol, + FormatBigDecimal.formatNumber(price), FormatBigDecimal.formatNumber(quantity), - FormatBigDecimal.formatNumber(total) + FormatBigDecimal.formatNumber(gross), + FormatBigDecimal.formatNumber(commission), + FormatBigDecimal.formatNumber(tax), + FormatBigDecimal.formatNumber(total), + FormatBigDecimal.formatNumber(profit) )); }; From 2a1b6c75eca0de7b37585fbae961fff6ac30870a Mon Sep 17 00:00:00 2001 From: Roar Date: Mon, 25 May 2026 22:01:31 +0200 Subject: [PATCH 6/8] Updated lang_en.properties Added strings for the new ui elements. --- millions/src/main/resources/i18n/lang_en.properties | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/millions/src/main/resources/i18n/lang_en.properties b/millions/src/main/resources/i18n/lang_en.properties index 0c7bae8..4ac2825 100644 --- a/millions/src/main/resources/i18n/lang_en.properties +++ b/millions/src/main/resources/i18n/lang_en.properties @@ -53,6 +53,7 @@ portfolioGross = Gross: portfolioCommission = Commission: portfolioTax = Tax: portfolioTotal = Total: +portfolioProfit = Profit: sellButton = Sell portfolioShareQuantity = Qty: portfolioBuyPrice = Buy price: @@ -62,4 +63,4 @@ portfolioCurrentPrice = Current Price: historyTitle=Transaction History historyTypePurchase=Purchase historyTypeSale=Sale -historyCellFormat=Week %d | %s | %s | Qty: %s | Total: $%s +historyCellFormat=Week %d | %s | %s | Price: %s | Qty: %s | Gross: %s | Commission: %s | Tax: %s | Total: $%s | Profit: %s From 0b51d200480e97e974bf9725bfa3e54461a5b060 Mon Sep 17 00:00:00 2001 From: Roar Date: Mon, 25 May 2026 22:01:49 +0200 Subject: [PATCH 7/8] Updated lang_no.properties Added strings for the new ui elements. --- millions/src/main/resources/i18n/lang_no.properties | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/millions/src/main/resources/i18n/lang_no.properties b/millions/src/main/resources/i18n/lang_no.properties index b61e8e7..faf680f 100644 --- a/millions/src/main/resources/i18n/lang_no.properties +++ b/millions/src/main/resources/i18n/lang_no.properties @@ -53,6 +53,7 @@ portfolioGross = Brutto: portfolioCommission = Kurtasje: portfolioTax = Skatt: portfolioTotal = Total: +portfolioProfit = Profitt: sellButton = Selg portfolioShareQuantity = Ant: portfolioBuyPrice = Kjøpspris: @@ -62,4 +63,4 @@ portfolioCurrentPrice = Gjeldende pris: historyTitle=Transaksjonshistorikk historyTypePurchase=Kjøp historyTypeSale=Salg -historyCellFormat=Uke %d | %s | %s | Ant: %s | Total: $%s \ No newline at end of file +historyCellFormat=Uke %d | %s | %s | Pris: %s | Ant: %s | Brutto: %s | Kurtasje: %s | Skatt: %s | Total: $%s | Profit: %s \ No newline at end of file From b92223cb30f2c0506e9a44ab61c8f112266eca94 Mon Sep 17 00:00:00 2001 From: Roar Date: Mon, 25 May 2026 22:02:14 +0200 Subject: [PATCH 8/8] Updated lang.properties Mirrored changes in lang_en. --- millions/src/main/resources/i18n/lang.properties | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/millions/src/main/resources/i18n/lang.properties b/millions/src/main/resources/i18n/lang.properties index 61c65d9..4ac2825 100644 --- a/millions/src/main/resources/i18n/lang.properties +++ b/millions/src/main/resources/i18n/lang.properties @@ -1,4 +1,4 @@ -# Default file to use if there is an error with language locale +# File for the english language # StartView newGame = New Game @@ -53,6 +53,7 @@ portfolioGross = Gross: portfolioCommission = Commission: portfolioTax = Tax: portfolioTotal = Total: +portfolioProfit = Profit: sellButton = Sell portfolioShareQuantity = Qty: portfolioBuyPrice = Buy price: @@ -62,4 +63,4 @@ portfolioCurrentPrice = Current Price: historyTitle=Transaction History historyTypePurchase=Purchase historyTypeSale=Sale -historyCellFormat=Week %d | %s | %s | Qty: %s | Total: $%s +historyCellFormat=Week %d | %s | %s | Price: %s | Qty: %s | Gross: %s | Commission: %s | Tax: %s | Total: $%s | Profit: %s