java - Why is my array storing multiple copies of the same value -


this output looks like:

name: [a, b, c, d] years flown: [1, 11, 7, 2] bonus amount: [0.0, 2410.0, 0.0, 2410.0, 1206.0, 0.0, 2410.0, 1206.0, 515.0] average traveled miles: 666.66 number earning bonus: 3 total bonus amounts: $10157.00 number of miles flown: [222.22, 555.55, 1000.0, 888.88] pilot count: 4 

can see what's wrong? i'm supposed getting 4 bonus amounts since there 4 names, these amounts. also, number earning bonus, there should 2 because can earn bonus number of miles flown greater average, shows 3 people earning bonus.

public class pilotbonus {    public static void main(string[] args) {               while (question.equalsignorecase("n")) {          if (pilotcount < max_pilots) {             pilotcount++;                    pilotname = getname(pilotname);             numyrsflown = getyrsflown(numyrsflown);             nummilesflown = getmilesflown(nummilesflown);             avgmilesflown = getavg(pilotcount, nummilesflown);             bonuseligibility = determine(avgmilesflown, nummilesflown);             bonusamt = getbonusamt(bonuseligibility, numyrsflown, bonusamt);             numearningbonus = getnumearningbonus(bonuseligibility, numyrsflown);             totalbonus = calctotalbonus(bonusamt);          }          else {             joptionpane.showmessagedialog(null, "too many pilots");          }           }                if (question.equalsignorecase("y")) {          print(pilotname, numyrsflown, bonusamt, avgmilesflown, numearningbonus,              totalbonus, nummilesflown, pilotcount);        }     }     public static boolean determine(double avgmilesflown, double[] nummilesflown) {        (double d : nummilesflown) {          if (d > avgmilesflown) {                     return true;          }                 }       return false;    }     public static double[] getbonusamt(boolean bonuseligibility, int[] numyrsflown, double[] bonusamt) {        double bonus = 0;        if (bonuseligibility == true) {          (int : numyrsflown) {                    if (i >= 9) {                bonus = 2410.00;             }             if (i < 9) {                bonus = 1206.00;             }             if (i < 6) {                bonus = 515.00;             }             if (i < 2) {                bonus = 0.00;             }              bonusamt = arrays.copyof(bonusamt, bonusamt.length + 1);             bonusamt[bonusamt.length - 1] = bonus;          }               }        return bonusamt;     }     public static int getnumearningbonus(boolean bonuseligibility, int[] numyrsflown) {        int count = 0;        (int : numyrsflown) {          if (i >= 2 && bonuseligibility == true) {             count++;          }       }        return count;    } 

you should remove double[] bonusamt parameter getbonusamt , add variable same name beginning of method

double[] bonusamt = new double[0]; 

Comments