From 521f600373e1c28a2fd74e269aec9e3b4e803a13 Mon Sep 17 00:00:00 2001 From: EspenTinius Date: Wed, 27 May 2026 01:02:10 +0200 Subject: [PATCH] commison on sale --- .../view/widgets/dashboard/DashBoardController.java | 13 +++++++------ .../mappe/view/widgets/dashboard/DashBoardView.java | 9 ++++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/dashboard/DashBoardController.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/dashboard/DashBoardController.java index beeb79d..0fa8f8c 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/dashboard/DashBoardController.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/dashboard/DashBoardController.java @@ -103,27 +103,27 @@ private void updatePreviews() { Stock current = getViewElement().getCurrentStock(); if (current == null) { getViewElement().updateCostPreview(0f, 0f); - getViewElement().updateSalePreview(0f, 0f); + getViewElement().updateSalePreview(0f, 0f, 0f); return; } String text = getViewElement().getQuantityInputField().getText(); if (!Validator.NOT_EMPTY.isValid(text)) { getViewElement().updateCostPreview(0f, 0f); - getViewElement().updateSalePreview(0f, 0f); + getViewElement().updateSalePreview(0f, 0f, 0f); return; } try { BigDecimal quantity = new BigDecimal(text); if (quantity.compareTo(BigDecimal.ZERO) <= 0) { getViewElement().updateCostPreview(0f, 0f); - getViewElement().updateSalePreview(0f, 0f); + getViewElement().updateSalePreview(0f, 0f, 0f); return; } updateCostPreview(current, quantity); updateSalePreview(current, quantity); } catch (IllegalArgumentException e) { getViewElement().updateCostPreview(0f, 0f); - getViewElement().updateSalePreview(0f, 0f); + getViewElement().updateSalePreview(0f, 0f, 0f); } } @@ -162,13 +162,13 @@ private void updateSalePreview(final Stock stock, final BigDecimal quantity) { List owned = player.getPortfolio().getShares(stock.getSymbol()); if (owned.isEmpty()) { - getViewElement().updateSalePreview(0f, 0f); + getViewElement().updateSalePreview(0f, 0f, 0f); return; } Share ownedPosition = owned.getFirst(); BigDecimal sellQuantity = quantity.min(ownedPosition.getQuantity()); if (sellQuantity.compareTo(BigDecimal.ZERO) <= 0) { - getViewElement().updateSalePreview(0f, 0f); + getViewElement().updateSalePreview(0f, 0f, 0f); return; } Share previewShare = new Share( @@ -177,6 +177,7 @@ private void updateSalePreview(final Stock stock, SaleCalculator calc = new SaleCalculator(previewShare); getViewElement().updateSalePreview( calc.calculateTotal().floatValue(), + calc.calculateCommission().floatValue(), calc.calculateTax().floatValue() ); } diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/dashboard/DashBoardView.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/dashboard/DashBoardView.java index 5304015..dd69d82 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/dashboard/DashBoardView.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/dashboard/DashBoardView.java @@ -581,20 +581,23 @@ public void updateCostPreview(final float cost, * Updates the sale preview labels, showing how much the * player would receive on their account if they sold the * chosen amount of currently owned shares right now - * (gross minus commission and tax), as well as the tax - * part of that calculation on its own. + * (gross minus commission and tax), as well as the + * commission and tax part of that calculation on their own. * * @param saleNet the estimated net amount received from * the sale in NOK (gross - commission - tax). + * @param commission the estimated commission in NOK. * @param tax the estimated tax in NOK. * */ public void updateSalePreview(final float saleNet, + final float commission, final float tax) { saleTotalPreviewLabel.setText( "Sale total: " + Math.round(saleNet * 100f) / 100f + " NOK" ); saleTaxPreviewLabel.setText( - "Tax: " + Math.round(tax * 100f) / 100f + " NOK" + "Commission: " + Math.round(commission * 100f) / 100f + " NOK" + + " Tax: " + Math.round(tax * 100f) / 100f + " NOK" ); }