1 00:00:00,150 --> 00:00:03,840 Before we start, did you try solving the workbook yourself? 2 00:00:03,870 --> 00:00:09,630 If not, please click the link in the resources folder and follow the instructions for this workbook. 3 00:00:11,020 --> 00:00:14,040 This video will present the solution to workbook 3.3. 4 00:00:14,050 --> 00:00:16,810 We're going to visualize the runtime again using code. 5 00:00:16,810 --> 00:00:21,010 So please make sure that you launch the exact folder that contains your java file. 6 00:00:21,040 --> 00:00:24,940 Do not, under any circumstance launch all of the resources at once. 7 00:00:24,940 --> 00:00:29,290 If your file explorer looks like this, you will not be able to visualize their runtime. 8 00:00:30,960 --> 00:00:31,440 All right. 9 00:00:31,440 --> 00:00:37,470 First, we need a variable that calculates the margin of points Gryffindor stored over Ravenclaw. 10 00:00:37,500 --> 00:00:46,170 So we can say int margin is equal to the amount of points by which Gryffindor stored over Ravenclaw. 11 00:00:47,120 --> 00:00:53,470 And the margin of points that Gryffindor scored over the other team will determine their ranking. 12 00:00:53,480 --> 00:01:00,380 So if Gryffindor wins by a margin of 300 points or greater. 13 00:01:02,420 --> 00:01:05,750 Then we're going to say Gryffindor takes the House Cup. 14 00:01:09,590 --> 00:01:14,210 Now, if this condition fails, that means Gryffindor did not earn enough points. 15 00:01:14,210 --> 00:01:20,620 So the next condition we're going to check for is if they won by any margin of points or tied. 16 00:01:20,630 --> 00:01:24,590 So if margin is greater than or equal to zero. 17 00:01:25,390 --> 00:01:29,680 If that happens to be the case, then they are in second place. 18 00:01:31,280 --> 00:01:32,750 So we're going to print. 19 00:01:34,760 --> 00:01:36,470 In second place Gryffindor. 20 00:01:36,980 --> 00:01:42,800 However, if the points margin happens to be less than zero, if Gryffindor actually loses to Ravenclaw, 21 00:01:42,830 --> 00:01:45,350 then this condition will also be false. 22 00:01:45,350 --> 00:01:52,190 So the next thing we have to check for is how much did they lose by if they lose within 100 points, 23 00:01:52,190 --> 00:01:56,180 if they lose by a margin of 100 points or less, then they are in third. 24 00:01:56,180 --> 00:02:03,410 So here we can say else if margin is greater than or equal to -100. 25 00:02:04,650 --> 00:02:08,699 Then they are in third and third place Gryffindor. 26 00:02:13,040 --> 00:02:19,400 Now, finally, if Gryffindor loses by more than 100 points, then this condition is also going to fail. 27 00:02:19,430 --> 00:02:27,440 So the last possible scenario that we can represent using else is where Gryffindor is in last place. 28 00:02:29,680 --> 00:02:30,550 Perfect. 29 00:02:31,540 --> 00:02:33,460 Now we can visualize the runtime. 30 00:02:33,460 --> 00:02:40,330 And if you want to visualize the runtime for a series of if elseif and else, what you want to do is 31 00:02:40,330 --> 00:02:43,570 only put one breakpoint at the very beginning. 32 00:02:43,900 --> 00:02:44,830 All right. 33 00:02:45,100 --> 00:02:45,910 And you know what? 34 00:02:45,910 --> 00:02:47,500 We'll put breakpoints here as well. 35 00:02:48,780 --> 00:02:53,940 And our first test case will be Gryffindor winning by a margin of 200 points. 36 00:02:53,940 --> 00:02:56,220 So let us visualize the runtime. 37 00:02:57,820 --> 00:02:59,560 Dismissing this window. 38 00:02:59,590 --> 00:03:00,610 All right. 39 00:03:00,610 --> 00:03:01,810 Cleaning up a little. 40 00:03:02,570 --> 00:03:08,990 So here it creates a points variable of 400 and then Ravenclaw score 200 points. 41 00:03:08,990 --> 00:03:12,850 So Gryffindor won by a margin of 200 points. 42 00:03:13,130 --> 00:03:17,210 A margin of 200 is not greater than or equal to 300. 43 00:03:17,210 --> 00:03:20,360 So unfortunately they are not in first place. 44 00:03:20,360 --> 00:03:22,190 Please don't press continue. 45 00:03:35,920 --> 00:03:38,140 We want to step over everything step by step. 46 00:03:38,140 --> 00:03:40,360 So we'll press the step over button. 47 00:03:40,660 --> 00:03:47,440 This is how you visualize a series of if if you put one breakpoint and then you keep stepping over. 48 00:03:47,470 --> 00:03:51,580 And now a margin of 200 is greater than or equal to zero. 49 00:03:51,580 --> 00:03:53,770 So this will evaluate to true. 50 00:03:53,770 --> 00:04:01,420 And Gryffindor is in second place and now you can press continue in test case number two, Gryffindor 51 00:04:01,420 --> 00:04:06,370 will score 850 points, whereas Ravenclaw scores 500. 52 00:04:06,400 --> 00:04:08,710 Let us re visualize the runtime. 53 00:04:11,950 --> 00:04:15,970 This time Gryffindor won by a points margin of 350. 54 00:04:16,000 --> 00:04:20,230 350 is greater than or equal to 300. 55 00:04:22,310 --> 00:04:26,970 So this condition evaluates to true, which means this statement will run. 56 00:04:26,990 --> 00:04:29,270 Gryffindor are the champions. 57 00:04:30,800 --> 00:04:31,700 All right. 58 00:04:33,430 --> 00:04:33,700 Test. 59 00:04:33,700 --> 00:04:41,770 Case number three is where Gryffindor scores 620 points, but Ravenclaw only scores 500. 60 00:04:42,130 --> 00:04:43,930 Let us visualize the runtime. 61 00:04:47,460 --> 00:04:51,180 This time Gryffindor won by a margin of 120 points. 62 00:04:51,210 --> 00:04:55,680 Now we're going to step over the chain of F, l, f, and L statements. 63 00:04:55,680 --> 00:05:00,270 So the margin of 120 is not greater than or equal to 300. 64 00:05:00,300 --> 00:05:05,610 This evaluates the false margin of 120 is greater than or equal to zero. 65 00:05:05,640 --> 00:05:10,380 This evaluates the true and Gryffindor will come in second place. 66 00:05:12,430 --> 00:05:12,820 All right. 67 00:05:12,850 --> 00:05:19,780 Test case number four is when Gryffindor scores 450 points, but Ravenclaw actually has more points 68 00:05:19,780 --> 00:05:20,410 than them. 69 00:05:20,650 --> 00:05:22,600 So let's visualize the runtime. 70 00:05:25,430 --> 00:05:31,560 So here it appears that Gryffindor lost by a margin of 50 points. 71 00:05:31,580 --> 00:05:34,670 -50 is not greater than or equal to 300. 72 00:05:34,700 --> 00:05:41,660 This evaluates the false the if statement does not execute -50 is not greater than or equal to zero. 73 00:05:41,660 --> 00:05:44,240 So this also evaluates the false. 74 00:05:45,770 --> 00:05:49,000 -50 is greater than or equal to -100. 75 00:05:49,010 --> 00:05:55,910 So Gryffindor did manage to only lose within 100 points, which means they will be in third place. 76 00:05:58,410 --> 00:06:00,060 Test case number five. 77 00:06:01,830 --> 00:06:03,040 100. 78 00:06:03,060 --> 00:06:04,080 500. 79 00:06:04,080 --> 00:06:07,590 This time Gryffindor loses by 400 points. 80 00:06:08,590 --> 00:06:11,700 So the margin of points is -400. 81 00:06:11,710 --> 00:06:13,330 That's how much they lost by. 82 00:06:15,280 --> 00:06:19,570 This is going to evaluate the false so the statement will not execute. 83 00:06:19,600 --> 00:06:25,240 This also evaluates the false because -400 is not greater than or equal to zero. 84 00:06:26,310 --> 00:06:31,510 This is also going to evaluate the faults because they did not lose within -100. 85 00:06:31,530 --> 00:06:33,870 They lost by 400 points. 86 00:06:34,080 --> 00:06:38,790 So we default to the statement where they are in fourth place. 87 00:06:40,000 --> 00:06:40,690 And that's all. 88 00:06:40,690 --> 00:06:43,120 I hope you enjoyed this breakpoint session.