Skip to content

Commit

Permalink
add javadoc to Stock and Share class
Browse files Browse the repository at this point in the history
  • Loading branch information
einaskoi committed Feb 25, 2026
1 parent aa7a05e commit bd0c477
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Share.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,24 @@

import java.math.BigDecimal;

/**
* Represents a share of a particular stock owned by a player.
* <p>
* A {@code Share} keeps track of the stock it represents, the quantity owned,
* and the purchase price at which it was bought.
* </p>
*/
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;
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Stock.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,24 @@
import java.util.ArrayList;
import java.util.List;

/**
* Represents a stock of a company in the {@link Exchange}.
* <p>
* 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.
* </p>
*/
public class Stock {
private final String symbol;
private final String company;
private List<BigDecimal> 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;
Expand All @@ -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);
}
Expand Down

0 comments on commit bd0c477

Please sign in to comment.