So i'm in ap computer science right now and ArrayList are confusing the **** out of me.

We're working on a program in which we have to create a method that adds an "ap exam class" to an ArrayList heres what it looks like:

private ArrayList<APExam> myExams;

myExams = new ArrayList<APExam>();

/**
* add an exam to myExams
*/
public void addExam(APExam e)
{



} 

any ideas? Thanks :)

Recommended Answers

Hi,

You can use the "add" method in the ArrayList class :
http://docs.oracle.com/javase/6/docs/api/java/util/ArrayList.html

// Add an exam in the end of the array list
myExams.add(e);

// Add an exam in a specific …
Jump to Post

All 4 Replies

Awesome it worked out! Simple ;p

but now im stuck on how to take all the ints in the arraylist and store it into 1 int:

    /**
     *  returns the student's average score on all exams
     */
    public double computeExamAverage()
    {



    } 

I tried making a for loop?

int total = 0;

           for(int i = 0; i < myExams.size(); i++)
                total = myExams.get(i);

But as you probably already know ArrayLists suck so it doesnt work.

so what i tried now was switching to for each loop still no good D:

int total = 0

for(APExam arg  : myExams)
           {
                total += arg;

           }

got it :D after messing with it for a while i found a .getScore method LOL

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.