找不到符号-method getvalue();也许你的意思是:intValue

时间:2011-01-26 04:41:32

标签: java programming-languages

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();
   }
}

3 个答案:

答案 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()));