I'm having a problem with my code and it seems that this portion seems to be causing it.
public static boolean[] determine(double avgMilesFlown, double[] numMilesFlown, boolean[] bonusEligibility) {
boolean result = false;
for (double d : numMilesFlown) {
if (d > avgMilesFlown) {
result = true;
}
}
bonusEligibility = Arrays.copyOf(bonusEligibility, bonusEligibility.length + 1);
bonusEligibility[bonusEligibility.length - 1] = result;
return bonusEligibility;
}
This block of code is supposed to determine if someone earns a bonus. If their number of miles flown is more than the average miles flown across all entered (including themselves) then they are eligible. My question is am I comparing each individual number of miles flown to the average of miles flown correctly, so that if the number of miles flown is greater than the average, then it will return a list of true's that correspond to each individual.
Normal for loop:
for (int i = 0; i < numMilesFlown.length; i++) {
if (numMilesFlown[i] > avgMilesFlown) {
result = true;
}
}
Example input/output:
Names: [tim, jim]
Years Flown: [2, 2]
Miles flown: [45, 43]
Avg Miles: 44
Bonus: [515.00, 515.00]
Only Tim should get a bonus because his miles flown is greater than the average, but Jim earns one too, even though his miles flown is below the average.
breakstatement afterresult=true; as apart of enhancement.