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:10,850 --> 00:00:13,570 This video will present the solution to workbook 2.1. 4 00:00:13,580 --> 00:00:18,170 Please make sure that you launched the exact folder that contains your Java file. 5 00:00:18,530 --> 00:00:23,690 So here we have a points, a variable that starts zero, and we need to keep updating the number of 6 00:00:23,690 --> 00:00:27,190 points in accordance with these print statements. 7 00:00:27,200 --> 00:00:33,860 First, Harry loses 50 points for Gryffindor, so here we have to say points minus equal 50. 8 00:00:33,890 --> 00:00:39,530 By saying that it updates the variable on the left by subtracting the value on the right. 9 00:00:39,530 --> 00:00:44,420 So once we reach this line, now points is going to equal -50. 10 00:00:45,050 --> 00:00:50,090 And next, Harry was being cheeky in class, this time losing Gryffindor. 11 00:00:50,120 --> 00:00:50,990 Three points. 12 00:00:50,990 --> 00:00:53,930 So here we have to say points. 13 00:00:55,080 --> 00:00:57,210 Minus equal three. 14 00:00:57,920 --> 00:01:01,730 So at this line, points should equal -53. 15 00:01:02,210 --> 00:01:06,080 But this time her mini wins 30 points for Gryffindor. 16 00:01:07,390 --> 00:01:17,020 So here by saying points plus equals 30, it updates the variable on the left by adding the value on 17 00:01:17,020 --> 00:01:17,920 the right. 18 00:01:18,680 --> 00:01:25,310 And now here run earned 100 points so we can add another 100 points to the points variable. 19 00:01:29,590 --> 00:01:34,020 And finally Harry redeemed himself and earned 60 points. 20 00:01:34,030 --> 00:01:38,860 So here I can add 60 to my points variable. 21 00:01:40,770 --> 00:01:42,990 And Task two is fairly easy. 22 00:01:42,990 --> 00:01:46,350 You simply need to print your final result and run your code. 23 00:01:46,350 --> 00:01:52,860 So here I will say system, dot, dot, print line, the final number of points. 24 00:01:53,490 --> 00:01:56,940 Now I will go run my code using terminal commands. 25 00:01:56,970 --> 00:01:58,830 Java C points. 26 00:01:58,830 --> 00:02:00,060 Dot Java. 27 00:02:03,260 --> 00:02:05,450 Java points. 28 00:02:06,610 --> 00:02:08,320 And we get the correct result. 29 00:02:08,320 --> 00:02:09,669 137. 30 00:02:10,490 --> 00:02:12,240 Let's visualize the runtime. 31 00:02:12,260 --> 00:02:18,920 The variable starts at zero, and in the first two cases it updates the points variable by subtracting 32 00:02:18,920 --> 00:02:20,360 the value on the right. 33 00:02:20,480 --> 00:02:26,630 In the last three cases, it updates the points variable by adding the value on the right, and the 34 00:02:26,630 --> 00:02:29,510 final result is 137.