1 00:00:00,400 --> 00:00:02,760 I'm going to show you two ways to do this. 2 00:00:02,760 --> 00:00:05,260 We know that for each student, we want to write 3 00:00:05,260 --> 00:00:08,189 that student's total into an array and return it. We 4 00:00:08,189 --> 00:00:10,280 also know exactly how big we want the array to 5 00:00:10,280 --> 00:00:14,180 be because we want one for each student. So I 6 00:00:14,180 --> 00:00:17,060 want numStudents items in my array. Now, for all of 7 00:00:17,060 --> 00:00:21,070 the student from the 0 student to the last student 8 00:00:22,290 --> 00:00:25,640 Going up one at a time. I want to fill that student's 9 00:00:25,640 --> 00:00:28,510 spot in the array of totals with that 10 00:00:28,510 --> 00:00:31,530 student's total. I already have a method that calculates 11 00:00:31,530 --> 00:00:35,500 this. So, I can use totalForStudent. And then, 12 00:00:35,500 --> 00:00:37,030 when I've done that for all of the students, 13 00:00:39,120 --> 00:00:41,470 I can return the totals. Looks like I forgot to 14 00:00:41,470 --> 00:00:45,490 call it totals. Let's check that it works. I'll run 15 00:00:45,490 --> 00:00:48,130 the tester, and it looks like it's got what I 16 00:00:48,130 --> 00:00:52,630 expecting. Now, we could use nested for loops. I'll still 17 00:00:52,630 --> 00:00:54,150 want all of my totals, and I'll still want to 18 00:00:54,150 --> 00:00:57,980 return them, but let's think about solving this problem for 19 00:00:57,980 --> 00:01:01,500 just one student, for each topic, starting with the first 20 00:01:01,500 --> 00:01:04,680 one. And we going up to the number of topics, 21 00:01:04,680 --> 00:01:07,010 one at a time. I'll add the score 22 00:01:07,010 --> 00:01:10,360 for that topic to that student's total, let's say 23 00:01:10,360 --> 00:01:13,120 for now I'm thinking about student 1. To 24 00:01:13,120 --> 00:01:16,670 calculate total for student 1, I'll start at 0 25 00:01:16,670 --> 00:01:19,600 and for each topic And want to add 26 00:01:19,600 --> 00:01:23,350 that student's grade, in that topic. Then, once I 27 00:01:23,350 --> 00:01:25,800 have the student total in my larger array 28 00:01:25,800 --> 00:01:30,160 totals, I'll set the total for that student to 29 00:01:30,160 --> 00:01:31,830 be the student total that I just calculated. 30 00:01:33,010 --> 00:01:34,540 So this is what I do for one student. 31 00:01:34,540 --> 00:01:36,300 And now, I want to do that for every single 32 00:01:36,300 --> 00:01:39,230 student. So that all of the spaces in total 33 00:01:39,230 --> 00:01:41,790 gets filled, so I will indent that a little 34 00:01:41,790 --> 00:01:46,250 bit and now for each student starting with the 35 00:01:46,250 --> 00:01:48,410 zeroth one so we don't need this line anymore 36 00:01:48,410 --> 00:01:50,960 I will go up to the number of students 37 00:01:53,380 --> 00:01:58,430 one at a time. I will do all of these steps. So 38 00:01:58,430 --> 00:02:03,440 now the inter-loop is calculating the student totals and the outer loop is 39 00:02:03,440 --> 00:02:08,699 storing the student totals in totals. So now we're fix up syntax errors. And 40 00:02:08,699 --> 00:02:11,130 this way should work just like the last one. I'll 41 00:02:11,130 --> 00:02:13,310 run it to make sure and it looks like it's 42 00:02:13,310 --> 00:02:17,010 still good. Hopefully the number of values you see here. 43 00:02:17,010 --> 00:02:18,480 Makes it obvious why it would be be nice as 44 00:02:18,480 --> 00:02:20,000 a teacher, have a computer do this for you.