I have an ArrayList that stores an inventory of cars. I want the user to input start year and end year and return a number of cars in inventory in the year range specified. I have to use a foreach loop and get all the years to display. How can I count them? Below is what I have so far
public int howManyBetweenTheseYears(int startYear, int endYear)
{
int totalYear = 0;
for(Lamborghini year : inventory)
{
if((year.getModelYear() >= startYear)
&& (year.getModelYear() <= endYear)) {
totalYear = year.getModelYear();
System.out.println(totalYear);
}
}