I need to determine which predator in my PredatorList array has received the most damage. For some reason when I try to return that predator, eclipse says - mostDamaged cannot be resolved to a variable.
Why is this so?
public Predator mostDamagedPredator() {
// test if PredatorList contains predators
if (PredatorList.length > 0){
float difference = 0;
for (int i = 0; i < PredatorList.length; i++) {
if (PredatorList[i].getMaxHitPoints() - PredatorList[i].getHitPoints() > difference){
Predator mostDamaged = PredatorList[i];
}
}
return mostDamaged; // ERROR - mostDamaged cannot be resolved to a variable
}
// return null if there are no predators in PredatorList
return null;
}
mostDamaged.Arrays.stream(PredatorList).max(Comparator.comparing(p -> p.getMaxHitPoints() - p.getHitPoints())). Further, in Java we usecamelCasefor variables,PascalCaseis reserves for classes - please always stick to this convention.