I'm trying to find the smallest value in an array list(iList). The array list contains multiple items (InventoryItem) each with their own description, cost, etc. I need to find the smallest cost, and return the item that has the smallest cost. Also, I have to use a while loop and not a for. Here is my code so far:
public InventoryItem itemWithLowestCost() {
int index = 0;
double smallest = 0;
while (index < iList.size()) {
if (!(smallest < iList.get(index).getCost())) {
smallest = iList.get(index).getCost();
}
if (iList.get(index).getCost() == smallest) {
return //what to put here? ;
}
index++;
}
}