diff --git a/src/main/java/edu/ntnu/idi/idatt/model/Exchange.java b/src/main/java/edu/ntnu/idi/idatt/model/Exchange.java index 3b96c81..e41a2c0 100644 --- a/src/main/java/edu/ntnu/idi/idatt/model/Exchange.java +++ b/src/main/java/edu/ntnu/idi/idatt/model/Exchange.java @@ -1,7 +1,6 @@ package edu.ntnu.idi.idatt.model; import java.math.BigDecimal; -import java.math.MathContext; import java.math.RoundingMode; import java.util.*; @@ -11,7 +10,6 @@ import edu.ntnu.idi.idatt.model.transaction.Purchase; import edu.ntnu.idi.idatt.model.transaction.Sale; import edu.ntnu.idi.idatt.model.transaction.Transaction; -import edu.ntnu.idi.idatt.session.UserSession; /** * Exchange class @@ -201,10 +199,7 @@ public void advance() { Random random = new Random(); stockMap.values() .forEach(s -> s.addNewSalesPrice(s.getSalesPrice() - .multiply(BigDecimal.valueOf(random.nextDouble(0.8, 1.4)).setScale(2, RoundingMode.HALF_UP)))); - UserSession.getInstance().netWorthProperty().set( - UserSession.getInstance().getPlayer().getNetWorth().doubleValue()); // TODO: Remove hook from here, just for - // testing + .multiply(BigDecimal.valueOf(random.nextDouble(0.8, 1.4))).setScale(2, RoundingMode.HALF_UP))); } } diff --git a/src/main/java/edu/ntnu/idi/idatt/view/SceneFactory.java b/src/main/java/edu/ntnu/idi/idatt/view/SceneFactory.java index cd14152..350fa89 100644 --- a/src/main/java/edu/ntnu/idi/idatt/view/SceneFactory.java +++ b/src/main/java/edu/ntnu/idi/idatt/view/SceneFactory.java @@ -20,19 +20,17 @@ import edu.ntnu.idi.idatt.view.primary.transactions.TransactionView; import javafx.scene.Parent; -import java.math.BigDecimal; import java.util.ArrayDeque; import java.util.Deque; -import java.util.List; public class SceneFactory { @FunctionalInterface - public interface MVCInitializer { + public interface MVCInitInterface { Parent execute(); } - private static Deque navigation = new ArrayDeque<>(); + private static Deque navigation = new ArrayDeque<>(); private static boolean navigatingBack = false; public static void goBack() { @@ -50,7 +48,7 @@ public static void reloadCurrent() { navigatingBack = false; } - private static void mark(MVCInitializer initializer) { + private static void mark(MVCInitInterface initializer) { if (!navigatingBack) { navigation.push(initializer); } @@ -62,6 +60,8 @@ public static boolean isFinal() { public static Parent createStartView() { + navigation.clear(); + StartModel model = new StartModel(); StartView view = new StartView(); StartController controller = new StartController(model); @@ -72,13 +72,14 @@ public static Parent createStartView() { return view.getInstance(); } - public static Parent createPortfolioView(){ + + public static Parent createPortfolioView() { mark(() -> createPortfolioView()); - + PortfolioModel model = new PortfolioModel(); PortfolioView view = new PortfolioView(); - PortfolioController controller = new PortfolioController(model); + PortfolioController controller = new PortfolioController(model); view.setModel(model); view.setController(controller); diff --git a/src/main/java/edu/ntnu/idi/idatt/view/components/elements/PlayerPortfolioComponent.java b/src/main/java/edu/ntnu/idi/idatt/view/components/elements/PlayerPortfolioComponent.java index 7457d36..6744dd4 100644 --- a/src/main/java/edu/ntnu/idi/idatt/view/components/elements/PlayerPortfolioComponent.java +++ b/src/main/java/edu/ntnu/idi/idatt/view/components/elements/PlayerPortfolioComponent.java @@ -8,42 +8,42 @@ import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; -import java.math.BigDecimal; -import java.math.RoundingMode; import java.util.ArrayList; import java.util.Collections; public class PlayerPortfolioComponent extends HBox { - public PlayerPortfolioComponent(Portfolio portfolio){ - this.setMaxSize(Double.MAX_VALUE, 500); - this.getStyleClass().add("light"); + public PlayerPortfolioComponent(Portfolio portfolio) { + this.setMaxSize(Double.MAX_VALUE, 500); + this.getStyleClass().add("light"); - Label userTitle = new Label(String.format("%s's Portfolio", UserSession.getInstance().getPlayer().getName())); - Label netWorth = new Label(); - netWorth.textProperty().bind( - UserSession.getInstance().netWorthProperty().asString("Net Worth: %.2f $")); - Label percentageChange = new Label("Percentage change: "+ UserSession.getInstance().netWorthProperty().doubleValue()); - Label playerStatus = new Label("Player status: "+ UserSession.getInstance().getPlayer().getStatus()); - Label totalShares = new Label("Total shares owned: "+ UserSession.getInstance().getPlayer().getPortfolio().getShares().size()); - ArrayList