WEBVTT 00:00:00.400 --> 00:00:02.760 I'm going to show you two ways to do this. 00:00:02.760 --> 00:00:05.260 We know that for each student, we want to write 00:00:05.260 --> 00:00:08.189 that student's total into an array and return it. We 00:00:08.189 --> 00:00:10.280 also know exactly how big we want the array to 00:00:10.280 --> 00:00:14.180 be because we want one for each student. So I 00:00:14.180 --> 00:00:17.060 want numStudents items in my array. Now, for all of 00:00:17.060 --> 00:00:21.070 the student from the 0 student to the last student 00:00:22.290 --> 00:00:25.640 Going up one at a time. I want to fill that student's 00:00:25.640 --> 00:00:28.510 spot in the array of totals with that 00:00:28.510 --> 00:00:31.530 student's total. I already have a method that calculates 00:00:31.530 --> 00:00:35.500 this. So, I can use totalForStudent. And then, 00:00:35.500 --> 00:00:37.030 when I've done that for all of the students, 00:00:39.120 --> 00:00:41.470 I can return the totals. Looks like I forgot to 00:00:41.470 --> 00:00:45.490 call it totals. Let's check that it works. I'll run 00:00:45.490 --> 00:00:48.130 the tester, and it looks like it's got what I 00:00:48.130 --> 00:00:52.630 expecting. Now, we could use nested for loops. I'll still 00:00:52.630 --> 00:00:54.150 want all of my totals, and I'll still want to 00:00:54.150 --> 00:00:57.980 return them, but let's think about solving this problem for 00:00:57.980 --> 00:01:01.500 just one student, for each topic, starting with the first 00:01:01.500 --> 00:01:04.680 one. And we going up to the number of topics, 00:01:04.680 --> 00:01:07.010 one at a time. I'll add the score 00:01:07.010 --> 00:01:10.360 for that topic to that student's total, let's say 00:01:10.360 --> 00:01:13.120 for now I'm thinking about student 1. To 00:01:13.120 --> 00:01:16.670 calculate total for student 1, I'll start at 0 00:01:16.670 --> 00:01:19.600 and for each topic And want to add 00:01:19.600 --> 00:01:23.350 that student's grade, in that topic. Then, once I 00:01:23.350 --> 00:01:25.800 have the student total in my larger array 00:01:25.800 --> 00:01:30.160 totals, I'll set the total for that student to 00:01:30.160 --> 00:01:31.830 be the student total that I just calculated. 00:01:33.010 --> 00:01:34.540 So this is what I do for one student. 00:01:34.540 --> 00:01:36.300 And now, I want to do that for every single 00:01:36.300 --> 00:01:39.230 student. So that all of the spaces in total 00:01:39.230 --> 00:01:41.790 gets filled, so I will indent that a little 00:01:41.790 --> 00:01:46.250 bit and now for each student starting with the 00:01:46.250 --> 00:01:48.410 zeroth one so we don't need this line anymore 00:01:48.410 --> 00:01:50.960 I will go up to the number of students 00:01:53.380 --> 00:01:58.430 one at a time. I will do all of these steps. So 00:01:58.430 --> 00:02:03.440 now the inter-loop is calculating the student totals and the outer loop is 00:02:03.440 --> 00:02:08.699 storing the student totals in totals. So now we're fix up syntax errors. And 00:02:08.699 --> 00:02:11.130 this way should work just like the last one. I'll 00:02:11.130 --> 00:02:13.310 run it to make sure and it looks like it's 00:02:13.310 --> 00:02:17.010 still good. Hopefully the number of values you see here. 00:02:17.010 --> 00:02:18.480 Makes it obvious why it would be be nice as 00:02:18.480 --> 00:02:20.000 a teacher, have a computer do this for you.