import java.util.ArrayList;
public class Averager {
private ArrayList list;
public Averager() {
list = new ArrayList();
}
public void addGrades(int test, int quiz) {
list.add(new Integer(test));
list.add(new Integer(test));
list.add(new Integer(quiz));
}
public double getAverage() {
int sum = 0;
for(int i = 0; i < list.size(); i++) {
sum += ((Integer)list.get(i)).getValue();
}
return sum / list.size();
}
}
答案 0 :(得分:3)
Integer类没有getValue()方法。有intValue()方法。但对于算术运算,您甚至不必调用它 - Java将执行autoboxing:
sum += (Integer)list.get(i);
答案 1 :(得分:1)
Class Integer没有方法 getValue
答案 2 :(得分:0)
sum += ((Integer)list.get(i)).intValue();
或
sum += ((Integer)list.get(i));
或
sum += (Integer.parseInt((list.get(i)).toString()));