I'm using command line arguments for this one:
public class Pg253E4 {
public static void main(String[]args) {
try {
System.out.println(Average.average(args)); // This part is saying I don't have a method in Average called average(String[] argName)
} catch(NullPointerException e) {
System.out.println(e.toString());
} catch(NumberFormatException e) {
System.out.println(e.toString());
} finally {
System.out.println("Nice job");
}
}
}
And this is the the other class:
public class Average {
public static double average(String[] arrayString) throws NullPointerException,NumberFormatException {
double sum=0;
double arrayStorage[] = new double[arrayString.length];
for(int i = 0; i< arrayString.length; i++) {
arrayStorage[i] = Double.parseDouble(arrayString[i]);
}
for(int i = 0; i<arrayString.length; i++) {
sum += arrayStorage[i];
}
return (sum/arrayString.length);
}
}
I don't understand why a syntax error pops up saying that I haven't declared or defined any method called average(String[] argName)
in the Average
class, when I clearly did.