开发者

cannot find symbol -method getvalue (); maybe you meant : intValue

import java.util.ArrayList;
public class Averager {

   private ArrayList list;

   public Averager() {
      list = new ArrayList();
   }

   publi开发者_JS百科c 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();
   }
}


Integer class does not have getValue() method. There is intValue() method. But for arithmetic operations you even don't have to call it - Java will do autoboxing:

sum += (Integer)list.get(i);


Class Integer doesn't have method getValue


sum += ((Integer)list.get(i)).intValue();

or

sum += ((Integer)list.get(i));

or

sum += (Integer.parseInt((list.get(i)).toString()));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜