Code:
ArrayList <Integer> marks = new ArrayList();
String output = "Class average:" + calculateAverage() + "\n" + "Maximum mark:" +
calculateMaximum() + "\n" +"Minimum mark:" + calculateMinimum() + "\n" + "Range of
marks:" + range;
analyzeTextArea.setText(output);
private double calculateAverage(double [] marks) {
double sum = 0;
for (int i=0; i< marks.length; i++) {
sum += marks[i];
}
return sum / marks.length;
}
Disregard the other things inside the string (minimum, maximum, and range) but for this line,
String output = "Class average:" + calculateAverage() + "\n" + "Maximum mark:" +
calculateMaximum() + "\n" +"Minimum mark:" + calculateMinimum() + "\n" + "Range of
marks:" + range;
I get an error:
required: double []
found: no arguments
Why do I get this error and what should I change?
You’re calling the method calculateAverage this way:
calculateAverage(), without any argument. But the method is declared this way:It thus needs one argument of type
double[], but you don’t pass anything.