for (Aircraft aircraft : landingQueue) {
if (aircraft.hasEmergency()) {
return aircraft;
}
}
for (Aircraft aircraft : landingQueue) {
if (aircraft.getFuelPercentRemaining() <= 20) {
return aircraft;
}
}
for (Aircraft aircraft : landingQueue) {
if (aircraft instanceof PassengerAircraft) {
return aircraft;
}
}
return landingQueue.get(0);
So my program runs through a list of aircraft in a queue and will return one based on the importance of a task. For instance, it will first check the landingQueue ArrayList to see if any aircraft are in an emergency and if it can't find one it then checks for aircraft with fuel less than 20 and so on. Is there a simple way to reduce the duplication of the for loop and if statement? Much appreciated