These are the methods I've been given, and they are all void. I want to access the results from the displaySearchResults using an appropriate loop, only reading data.
Anyone know what I need to do to pull the results from the 3 prior search methods?
/**
* Searches inventory by model
* @param model is the model you'd like to find
*/
public void searchByModel(String model){
ArrayList<Vehicle> results = new ArrayList();
for(int i = 0; i < vehicles.size(); i++){
if(vehicles.get(i).getModel().equalsIgnoreCase(model)){
results.add(vehicles.get(i));
}
}
}
/**
* Searches inventory by year
* @param year is the year you'd like to find
*/
public void searchByYear(int year){
ArrayList<Vehicle> results = new ArrayList();
for(int i = 0; i < vehicles.size(); i++){
if(vehicles.get(i).getYear() == year){
results.add(vehicles.get(i));
}
}
}
/**
* Searches inventory by price
* @param minPrice is the lowest price you'd like to search by
* @param maxPrice is the highest price you'd like to search by
*/
public void searchByPrice(double minPrice, double maxPrice){
ArrayList<Vehicle> results = new ArrayList();
for(int i = 0; i < vehicles.size(); i++){
if(vehicles.get(i).getSellingPrice() < maxPrice &&
vehicles.get(i).getSellingPrice() > minPrice){
results.add(vehicles.get(i));
}
}
}
/**
* @return Displays search results, unsure of how to get this working still
*/
public void displaySearchResults(ArrayList<Vehicle> results){
for(Vehicle vehicle : results){
}
resultsfrom outside eachsearchByXXmethod, it's a local variable