java - Trouble Writting a display method -
this first time asking question on here.
please give , if can, bit of guidance.
public class vacationscale { int [] vacationdays; int yearsofservice; public void setvacationscale() { vacationdays = new int[7]; vacationdays[0] = 10; vacationdays[1] = 15; vacationdays[2] = 15; vacationdays[3] = 15; vacationdays[4] = 20; vacationdays[5] = 20; vacationdays[6] = 25; public static void displayvacationdays(){ if(yearsofservice >=0){ system.out.println("vacation days " + vacationdays[yearsofservice]); } else { system.out.println("invaild years of service"); } } } }
everything fine until write method, eclipse telling me
"illegal modifier parameter displayvacationdays; final permitted"
and when seek final doesn't not work either. ( knew final wouldn't work, thought id seek though)
public static void displayvacationdays(){ if(yearsofservice >=0){ system.out.println("vacation days " + vacationdays[yearsofservice]); } else { system.out.println("invaild years of service"); } }
any thoughts on how can method work?
thanks :)
you accessing instance info within public static void displayvacationdays(){. so, declare non-static:
public void c(){..}
not as:
public static void displayvacationdays(){..}
and, have setvacationscale function separate function, no nesting
java arrays if-statement methods
No comments:
Post a Comment