Skip to content

Commit

Permalink
Added new methods to Stock class
Browse files Browse the repository at this point in the history
  • Loading branch information
elisab3 committed Mar 24, 2026
1 parent c070a67 commit 2459139
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/main/java/Stock.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,28 @@ public BigDecimal getSalesPrice() {
public void addNewSalesPrice(BigDecimal price) {
prices.add(price);
}

public List<BigDecimal> getHistoricalPrices() {
return new ArrayList<>(prices); // returnerer en kopi for å beskytte selve listen
}

public BigDecimal getHighestPrice() {
return prices.stream()
.reduce(prices.get(0), BigDecimal::max);
}

public BigDecimal getLowestPrice() {
return prices.stream()
.reduce(prices.get(0), BigDecimal::min);
}

public BigDecimal getLatestPriceChange() {
if (prices.size() < 2) {
return BigDecimal.ZERO;
}

BigDecimal latest = prices.get(prices.size() - 1);
BigDecimal previous = prices.get(prices.size() - 2);
return latest.subtract(previous);
}
}
Binary file modified target/classes/Stock.class
Binary file not shown.

0 comments on commit 2459139

Please sign in to comment.