Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/main/java/millions/Stock.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,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);
}
}