Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Extending ArrayList Object - Help Needed!

843789Nov 3 2009 — edited Nov 4 2009
Hi Guys , I am rather new to Java and I am trying to extend the ArrayList object to that when an ArrayList of Integers exists it has a function to return the Average value of the Integers within the ArrayList. Below is the code I have so far:
import java.util.*;*
*import java.lang.*;
public class MathArrayList<Integer> extends ArrayList<Integer> {

double average;

public double Average() {
CalculateAverage();

return average;
}

private void CalculateAverage() {
double total = 0;

for(int i = 0; i < size(); i++) { 

total += get(i).intValue();
}

average = total / size();
}
}
When I attempt to compile this code I get: Cannot find symbol - Line 18 - ".intValue()" and I cannot work out why! I have created a smaller java project to test that I am using the method '.intValue()' correctly and it is converting and Integer to an int fine! Why cannot it not find a symbol?

Any help/comments if much appricated!

Thanks, Stewart
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 2 2009
Added on Nov 3 2009
10 comments
253 views