I'm going to show you two ways to do this.
We know that for each student, we want to write
that student's total into an array and return it. We
also know exactly how big we want the array to
be because we want one for each student. So I
want numStudents items in my array. Now, for all of
the student from the 0 student to the last student
Going up one at a time. I want to fill that student's
spot in the array of totals with that
student's total. I already have a method that calculates
this. So, I can use totalForStudent. And then,
when I've done that for all of the students,
I can return the totals. Looks like I forgot to
call it totals. Let's check that it works. I'll run
the tester, and it looks like it's got what I
expecting. Now, we could use nested for loops. I'll still
want all of my totals, and I'll still want to
return them, but let's think about solving this problem for
just one student, for each topic, starting with the first
one. And we going up to the number of topics,
one at a time. I'll add the score
for that topic to that student's total, let's say
for now I'm thinking about student 1. To
calculate total for student 1, I'll start at 0
and for each topic And want to add
that student's grade, in that topic. Then, once I
have the student total in my larger array
totals, I'll set the total for that student to
be the student total that I just calculated.
So this is what I do for one student.
And now, I want to do that for every single
student. So that all of the spaces in total
gets filled, so I will indent that a little
bit and now for each student starting with the
zeroth one so we don't need this line anymore
I will go up to the number of students
one at a time. I will do all of these steps. So
now the inter-loop is calculating the student totals and the outer loop is
storing the student totals in totals. So now we're fix up syntax errors. And
this way should work just like the last one. I'll
run it to make sure and it looks like it's
still good. Hopefully the number of values you see here.
Makes it obvious why it would be be nice as
a teacher, have a computer do this for you.