Before we start, did you try solving the workbook yourself?
If not, please click the link in the resources folder and follow the instructions for this workbook.
This video will present the solution to workbook 2.1.
Please make sure that you launched the exact folder that contains your Java file.
So here we have a points, a variable that starts zero, and we need to keep updating the number of
points in accordance with these print statements.
First, Harry loses 50 points for Gryffindor, so here we have to say points minus equal 50.
By saying that it updates the variable on the left by subtracting the value on the right.
So once we reach this line, now points is going to equal -50.
And next, Harry was being cheeky in class, this time losing Gryffindor.
Three points.
So here we have to say points.
Minus equal three.
So at this line, points should equal -53.
But this time her mini wins 30 points for Gryffindor.
So here by saying points plus equals 30, it updates the variable on the left by adding the value on
the right.
And now here run earned 100 points so we can add another 100 points to the points variable.
And finally Harry redeemed himself and earned 60 points.
So here I can add 60 to my points variable.
And Task two is fairly easy.
You simply need to print your final result and run your code.
So here I will say system, dot, dot, print line, the final number of points.
Now I will go run my code using terminal commands.
Java C points.
Dot Java.
Java points.
And we get the correct result.
137.
Let's visualize the runtime.
The variable starts at zero, and in the first two cases it updates the points variable by subtracting
the value on the right.
In the last three cases, it updates the points variable by adding the value on the right, and the
final result is 137.