Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into feat/prettify
Browse files Browse the repository at this point in the history
  • Loading branch information
martin committed May 26, 2026
2 parents d7c9b06 + 381a64d commit 2d2cbd3
Show file tree
Hide file tree
Showing 23 changed files with 149 additions and 87 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Millions stock trading game

Made by:
- Nikolai Oliver Aasheim Lydvo
- Martin Olai Amundsen Henøen

How to run the game:
1. Download the latest release
2. Ensure you have Java 25 and the Maven commandline tool installed
3. Navigate to the project root directory and run the command: "mvn javafx:run"
4. Set up your game configuration and start game

This file was deleted.

16 changes: 9 additions & 7 deletions src/main/java/millions/model/Share.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ public class Share {

/**
* @param stock Which stock the share is for.
* @param quantity How many stocks
* @param purchasePrice Purchase price of the share
* @throws IllegalArgumentException
* @param quantity How many stocks.
* @param purchasePrice Purchase price of the share.
* @throws IllegalArgumentException if stock is null.
* @throws IllegalArgumentException if quantity is null.
* @throws IllegalArgumentException if purchasePrice is null.
*/
public Share(Stock stock, BigDecimal quantity, BigDecimal purchasePrice) {
this.stock = stock;
Expand All @@ -30,27 +32,27 @@ public Share(Stock stock, BigDecimal quantity, BigDecimal purchasePrice) {
}
}

/** Share() with int quantity */
/** Share() with int quantity. */
public Share(Stock stock, int quantity, BigDecimal purchasePrice) {
this(stock, BigDecimal.valueOf(quantity), purchasePrice);
}

/**
* @return
* @return Stock object.
*/
public Stock getStock() {
return this.stock;
}

/**
* @return
* @return BigDecimal: quantity.
*/
public BigDecimal getQuantity() {
return this.quantity;
}

/**
* @return
* @return BigDecimal PurchasePrice.
*/
public BigDecimal getPurchasePrice() {
return this.purchasePrice;
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/millions/model/Stock.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,48 +38,49 @@ public Stock(String symbol, String company, List<BigDecimal> prices, List<BigDec
}
}

/** Stock() with single price instead of list */

/** Stock() with single price instead of list. */
public Stock(String symbol, String company, BigDecimal initialPrice, List<BigDecimal> volatilityFunctions) {
this(symbol, company, new ArrayList<>(List.of(initialPrice)), volatilityFunctions);
}

/**
* @return
* @return String: symbol.
*/
public String getSymbol() {
return this.symbol;
}

/**
* @return
* @return String: company.
*/
public String getCompany() {
return this.company;
}

/**
* @return
* @return BigDecimal: price.
*/
public BigDecimal getSalesPrice() {
return this.prices.getLast();
}

/**
* @param price Sales price
* @param price Sales price.
*/
public void addNewSalesPrice(BigDecimal price) {
this.prices.add(price);
}

/**
* @return
* @return BigDecimal list of prices.
*/
public List<BigDecimal> getHistoricalPrices() {
return this.prices;
}

/**
* @return
* @return BigDecimal highest recorded price.
*/
public BigDecimal getHighestPrice() {
BigDecimal highestPrice = this.prices.get(0);
Expand All @@ -92,7 +93,7 @@ public BigDecimal getHighestPrice() {
}

/**
* @return
* @return BigDecimal lowest recorded price.
*/
public BigDecimal getLowestPrice() {
BigDecimal lowestPrice = this.prices.get(0);
Expand All @@ -105,7 +106,7 @@ public BigDecimal getLowestPrice() {
}

/**
* @return
* @return BigDecimal price difference from last week
*/
public BigDecimal getLatestPriceChange() {
if (this.prices.size() < 2) {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/millions/model/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,30 @@ protected Transaction(Share share, int week, TransactionCalculator transactionCa
this.committed = false;
}

/**
* @return Share object
*/
public Share getShare() {
return this.share;
}

/**
* @return int: week
*/
public int getWeek() {
return this.week;
}

/**
* @return TransactionCalculator object
*/
public TransactionCalculator getCalculator() {
return this.transactionCalculator;
}

/**
* @return Boolean: status
*/
public boolean isCommitted() {
return this.committed;
}
Expand Down
27 changes: 26 additions & 1 deletion src/main/java/millions/model/TransactionArchive.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ public TransactionArchive() {
this.transactions = new ArrayList<>();
}

/**
* Adds a transaction to the archive
* @param transaction transaction object
* @return Boolean for success
*/
public boolean add(Transaction transaction) {
if (transactions.contains(transaction)) {
return false;
Expand All @@ -21,25 +26,45 @@ public boolean add(Transaction transaction) {
return true;
}

/**
* @return Boolean
*/
public boolean isEmpty() {
return transactions.isEmpty();
}

/**
* @return List of transaction objects
*/
public List<Transaction> getTransactions() {
return new ArrayList<>(transactions);
}

/**
* returns transaction processed in a given week
* @param week int
* @return List of transaction objects
*/
public List<Transaction> getTransactions(int week) {
return transactions.stream().filter(x -> x.getWeek() == week).collect(Collectors.toList());
}

/**
* Returns all purchase transactions in a given week
* @param week int
* @return List of transaction objects
*/
public List<Purchase> getPurchases(int week) {
return transactions.stream()
.filter(t -> t.getWeek() == week && t instanceof Purchase)
.map(t -> (Purchase) t)
.collect(Collectors.toList());
}

/**
* Returns all sale transactions in a given week
* @param week int
* @return List of transaction objects
*/
public List<Sale> getSales(int week) {
return transactions.stream()
.filter(t -> t.getWeek() == week && t instanceof Sale)
Expand Down
33 changes: 30 additions & 3 deletions src/main/java/millions/view/GameView.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,15 @@ public class GameView extends BorderPane implements PlayerListener, ExchangeList
}

private final Runnable onSellAllAndQuit;
private final TabPane tabPane;
private boolean updatingQuantityControls;

public GameView(GameController controller, Runnable onSellAllAndQuit) {
this.controller = controller;
this.onSellAllAndQuit = onSellAllAndQuit;
this.tabPane = createTabs();
setTop(createHeader());
setCenter(createTabs());
setCenter(tabPane);
configureStocksList();
configureButtons();
configureQuantityControls();
Expand Down Expand Up @@ -262,11 +264,33 @@ protected void updateItem(String profit, boolean empty) {
getStyleClass().add(profit.startsWith("-") ? "status-error" : "status-success");
}
});

TableColumn<Share, Share> marketColumn = new TableColumn<>("Market");
marketColumn.setMinWidth(100);
marketColumn.setStyle("-fx-alignment: CENTER;");
marketColumn.setCellFactory(column -> new TableCell<Share, Share>() {
private final Button button = new Button("Market Page");

@Override
protected void updateItem(Share share, boolean empty) {
super.updateItem(share, empty);

if (empty) {
setGraphic(null);
} else {
button.setOnAction(event -> {
Share s = getTableView().getItems().get(getIndex());
getTabPane().getSelectionModel().select(0);
stocksList.getSelectionModel().select(s.getStock());
showStockChart(s.getStock());
});
setGraphic(button);
}
}
});
portfolioTable
.getColumns()
.addAll(
symbolColumn, quantityColumn, purchasePriceColumn, currentPriceColumn, profitColumn);
symbolColumn, quantityColumn, purchasePriceColumn, currentPriceColumn, profitColumn, marketColumn);
return new Tab("Portfolio", portfolioTable);
}

Expand Down Expand Up @@ -662,6 +686,9 @@ private int getCurrentMaxBuyable() {
return Math.max(1, controller.getMaxBuyableQuantity(selected.getSymbol()));
}

public TabPane getTabPane() {
return this.tabPane;
}
private String formatStock(Stock stock) {
return ViewUtils.formatStock(stock);
}
Expand Down
27 changes: 27 additions & 0 deletions src/test/java/millions/controller/GameControllerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package millions.controller;

import millions.controller.fileIO.UncheckedFileNotFoundException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.math.BigDecimal;
import java.nio.file.Path;

import static org.junit.jupiter.api.Assertions.assertThrows;

public class GameControllerTest {
GameController gameController;
@BeforeEach
public void setUpController() {
this.gameController = new GameController();
}

@Test
public void startGameFileNotFoundTest() {
String name = "name";
BigDecimal startingMoney = new BigDecimal("100");
Path stockFilePath = Path.of("nonexistantfile");
int prerunWeeks = 1;
assertThrows(UncheckedFileNotFoundException.class, () -> {gameController.startGame(name,startingMoney,stockFilePath,prerunWeeks);});
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package millions;
package millions.controller.fileIO.CSV;

import millions.controller.fileIO.CSV.CSVStockFileParser;
import millions.controller.fileIO.InvalidFormatException;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;


import java.util.ArrayList;
import java.util.List;


Expand All @@ -18,8 +17,8 @@ public class CSVStockFileParserTest {
static String exampleString;
final CSVStockFileParser parser = new CSVStockFileParser();

@BeforeAll
public static void setUpTestString() {
@BeforeEach
public void setUpTestString() {
exampleString = "# Top 500 US Stocks by Market Cap\n";
exampleString += "# Ticker,Name,Price\n";
exampleString += "\n";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package millions;
package millions.controller.fileIO.CSV;

import millions.controller.fileIO.StockFileReader;
import org.junit.jupiter.api.BeforeAll;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
package millions;
package millions.model;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import millions.model.Exchange;
import millions.model.ExchangeListener;
import millions.model.Player;
import millions.model.Purchase;
import millions.model.Sale;
import millions.model.Share;
import millions.model.Stock;
import millions.model.Transaction;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand Down
Loading

0 comments on commit 2d2cbd3

Please sign in to comment.