For my method double lastPriceChange() if there are two or more prices in the array, it will return the difference between the last two (previous - last), if there are fewer items in the array then it should just return ZERO.
I am stuck on how I should start my if statements
I am stuck on how I should start my if statements
//Fields
double lastPChange;
double[] dailyPrices;
int numberOfDaysWithData;
public void addTrade(double price)
{
dailyPrices[numberOfDaysWithData] = price;
numberOfDaysWithData = numberOfDaysWithData + 1;
this.numberOfDaysWithData++;
lastPChange = (numberOfDaysWithData - 2);
}
public int numTrades()
{
return numberOfDaysWithData;
}
public double lastPriceChange()
{
return ;
}