I know this question is simple but i cant figure it out. My ArrayList "elemente" contains a number of double values. I have written the sum()-Method to add up all the values which works fine on its own. The normalize()- Method intends to divide the individual double values of "elemente" by the sum() and add them into the new ArrayList "normalized".
When trying to compile this code i get the error : " error: cannot find symbol: method sum()".
I have been trying to figure this out for about 2 hours now, so any help you can give me would be greatly appreciated :)
import java.io.*;
import java.util.*;
class Measurement {
public Measurement() {
this.elemente = new ArrayList<Double>();
}
public void setArray(String s){
try {
FileInputStream fis = new FileInputStream(s);
InputStreamReader isr = new InputStreamReader(fis);
BufferedReader br = new BufferedReader(isr);
String eingabe;
eingabe = br.readLine();
while (eingabe != null) {
elemente.add(Double.parseDouble(eingabe));
eingabe = br.readLine();
}
}
catch (Exception e) {
System.out.println("Hi");
}
}
public double sum(){
double result = 0.0;
Iterator<Double> e = elemente.iterator();
while (e.hasNext()) {
result += e.next();
}
return result;
}
public double min(){
return Collections.min(elemente);
}
public double max(){
return Collections.max(elemente);
}
public double mean(){
double result = 0.0;
double count = 0.0;
Iterator<Double> e = elemente.iterator();
while (e.hasNext()) {
result += e.next();
count += 1;
}
return result/count;
}
public ArrayList normalize(){
ArrayList<Double> normalized = new ArrayList<Double>();
Iterator<Double> e = elemente.iterator();
while (e.hasNext()) {
normalized.add(e.next()/elemente.sum()); // I cant call the prevously definded Method sum() here.
}
return normalized;
}
private ArrayList<Double> elemente;
}