Skip to content

Commit

Permalink
Merge pull request #26 from IDATT2003-gruppe06/2-add-new-methods-to-s…
Browse files Browse the repository at this point in the history
…tock-class

Completed issue: add new methods to stock class
  • Loading branch information
nolydvo authored Mar 10, 2026
2 parents 61c5e90 + 4efe591 commit 49c4952
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/main/java/millions/Stock.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,35 @@ public BigDecimal getSalesPrice() {
public void addNewSalesPrice(BigDecimal price) {
this.prices.add(price);
}

public List<BigDecimal> getHistoricalPrices() {
return this.prices;
}

public BigDecimal getHighestPrice() {
BigDecimal highestPrice = this.prices.get(0);
for (BigDecimal price : this.prices) {
if (price.compareTo(highestPrice) > 0) {
highestPrice = price;
}
}
return highestPrice;
}

public BigDecimal getLowestPrice() {
BigDecimal lowestPrice = this.prices.get(0);
for (BigDecimal price : this.prices) {
if (price.compareTo(lowestPrice) < 0) {
lowestPrice = price;
}
}
return lowestPrice;
}

public BigDecimal getLatestPriceChange() {
BigDecimal currentPrice = this.prices.getLast();
BigDecimal lastPrice = this.prices.get(this.prices.size() - 2);

return currentPrice.subtract(lastPrice);
}
}

0 comments on commit 49c4952

Please sign in to comment.