user1419306
user1419306

Reputation: 799

required: double [] found: no arguments

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?

Upvotes: 2

Views: 2413

Answers (4)

Kumar Vivek Mitra
Kumar Vivek Mitra

Reputation: 33544

private double calculateAverage(double [] marks) is the method declaration, so when its called it must have and argument of double array

eg:

calculateAverage(double_value_array);

Upvotes: 1

Eduardo Andrade
Eduardo Andrade

Reputation: 966

You can call it this way:

double d[] = {1, 2, 3};
double ret = calculateAverage(d);
System.out.println(ret);

Upvotes: 0

Jon Skeet
Jon Skeet

Reputation: 1502076

Look at this:

String output = "Class average:" + calculateAverage() + ...

What's that meant to be calculating the average of? You've got to provide the method with some data to average. The same is going to be true of calculateMaximum, calculateMinimum etc. Without any context, those methods can't do anything.

Where are your actual marks stored? Presumably you have some sort of variable storing the marks - so pass that. For example:

String output = "Class average:" + calculateAverage(actualMarks) + ...

... except obviously with the real variable, or whatever you're using to store the marks.

Upvotes: 3

JB Nizet
JB Nizet

Reputation: 691933

You're calling the method calculateAverage this way: calculateAverage(), without any argument. But the method is declared this way:

private double calculateAverage(double [] marks) 

It thus needs one argument of type double[], but you don't pass anything.

Upvotes: 7

Related Questions