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 6472647..c3f33af 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
@@ -7,7 +7,7 @@
/**
* 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.
+ * Each 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.
*
*/
@@ -17,7 +17,7 @@ public class Stock {
private List prices = new ArrayList<>();
/**
- * Constructs a new {@code Stock} with the given symbol, company name, and initial sales price.
+ * Constructs a new 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
@@ -45,7 +45,22 @@ public BigDecimal getSalesPrice() {
*
* @param salesPrice the new sales price to add
*/
- public void addNewSalesPrices(BigDecimal salesPrice) {
+ public void addNewSalesPrice(BigDecimal salesPrice) {
prices.add(salesPrice);
}
+
+ public List getHistoricalPrices() {
+ return List.copyOf(prices);
+ }
+
+ public BigDecimal getHighestPrice() {
+ return prices.stream().max(BigDecimal::compareTo).orElse(BigDecimal.ZERO);
+ }
+ public BigDecimal getLowestPrice() {
+ return prices.stream().min(BigDecimal::compareTo).orElse(BigDecimal.ZERO);
+ }
+
+ public BigDecimal getLatestPrice() {
+ return prices.isEmpty() ? BigDecimal.ZERO : prices.get(prices.size() - 1);
+ }
}
diff --git a/src/test/java/edu/ntnu/idi/idatt2003/gruppe42/Model/StockTest.java b/src/test/java/edu/ntnu/idi/idatt2003/gruppe42/Model/StockTest.java
index db17efb..396be27 100644
--- a/src/test/java/edu/ntnu/idi/idatt2003/gruppe42/Model/StockTest.java
+++ b/src/test/java/edu/ntnu/idi/idatt2003/gruppe42/Model/StockTest.java
@@ -20,7 +20,7 @@ void stockPropertiesTest() {
void addNewPriceTest() {
Stock stock = new Stock("AAPL", "Apple Inc.", new BigDecimal("100"));
BigDecimal newPrice = new BigDecimal("110");
- stock.addNewSalesPrices(newPrice);
+ stock.addNewSalesPrice(newPrice);
assertEquals(0, newPrice.compareTo(stock.getSalesPrice()));
}