Lydz - 1 month ago 11

Java Question

I am trying to get the mean rainfall for a certain year. When I try this I get a failure.

`Incorrect mean rainfall for a year expected: <80.19> but was <8.341666666666667>`

I think this means I am calculating the mean over ten years instead of a certain mean value for a specified year. But I'm not sure what to do because I ran it before and it was working and now it isn't :(

`public double calculateMeanRainfallYear(int Year){`

double sum = 0;

for(int counter = 0;counter<rainfallYears.length;counter++){

sum = rainfallYears[counter].calculateMeanRainfall();

}

return sum/rainfallYears.length;

}

I hope this is specific enough,

Thank you.

Answer

I doubt if it ever ran and gave correct results. This looks suspicious for calculating mean:

```
for(int counter = 0;counter<rainfallYears.length;counter++){
sum = rainfallYears[counter].calculateMeanRainfall();
}
return sum/rainfallYears.length;
```

Also, int Year is not being used anywhere.