From bd0c4773ba35f74041307308ed5f636b15f7757d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Einar=20Sk=C3=B8ien?= Date: Wed, 25 Feb 2026 11:09:54 +0100 Subject: [PATCH] add javadoc to Stock and Share class --- .../idi/idatt2003/gruppe42/Model/Share.java | 13 +++++++++++++ .../idi/idatt2003/gruppe42/Model/Stock.java | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Share.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Share.java index 41c7ed1..8f645dc 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Share.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Share.java @@ -2,11 +2,24 @@ import java.math.BigDecimal; +/** + * Represents a share of a particular stock owned by a player. + *

+ * A {@code Share} keeps track of the stock it represents, the quantity owned, + * and the purchase price at which it was bought. + *

+ */ public class Share { private Stock stock; private BigDecimal quantity; private BigDecimal purchasePrice; + /** + * Constructs a new {@code Share} given the given stock, quantity, and purchase price. + * @param stock stock the stock that this share represents + * @param quantity quantity the number of shares owned + * @param purchasePrice purchasePrice the price per share at the time of purchase + */ public Share(Stock stock, BigDecimal quantity, BigDecimal purchasePrice) { this.stock = stock; this.quantity = quantity; 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 bd4192c..6472647 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 @@ -4,11 +4,24 @@ import java.util.ArrayList; import java.util.List; +/** + * Represents a stock of a company in the {@link Exchange}. + *

+ * Each {@code Stock} has a unique symbol, a company name, and a history of sales prices. + * You can retrieve the current price or add new prices as the market changes. + *

+ */ public class Stock { private final String symbol; private final String company; private List prices = new ArrayList<>(); + /** + * Constructs a new {@code Stock} with the given symbol, company name, and initial sales price. + * @param symbol symbol the unique stock symbol (e.g., "AAPL") + * @param company company the company name (e.g., "Apple Inc.") + * @param salesPrice salesPrice the initial sales price of the stock + */ public Stock(String symbol, String company, BigDecimal salesPrice) { this.symbol = symbol; this.company = company; @@ -27,6 +40,11 @@ public BigDecimal getSalesPrice() { return prices.get(prices.size() - 1); } + /** + * Adds a new sales price to the stock's price history. + * + * @param salesPrice the new sales price to add + */ public void addNewSalesPrices(BigDecimal salesPrice) { prices.add(salesPrice); }