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 3.4.
Once again, we're going to visualize the runtime using VS code.
You know the drill.
Make sure that you launch the exact folder that contains your java file.
If you want to be able to visualize the runtime.
All right.
The workbook starts with a temperature in Celsius, 25 degrees Celsius.
And there's also a string variable forecast that equals an empty string, which makes sense because
we need to update this variable to a forecast based on the current temperature.
So first, we're going to say if.
The temperature is smaller than or equal to negative one degree Celsius and the forecast is freezing.
Stay home.
If this condition fails, that means the temperature is higher than negative one degrees Celsius.
So in the next condition else, if we're going to check if the temperature is less than or equal to
ten.
If that's the case, then the forecast is chilly.
Wear a coat.
But if this condition is also false, that means the temperature is actually higher than ten.
So in that case, we can say otherwise else.
The forecast is warm.
Go outside.
All right.
And depending on which condition executes, forecast is going to equal one of these values.
And then we're printing the forecast.
Let's visualize the runtime.
So test case number one is when the temperature equals 25.
We're going to put breakpoints here, here.
And remember, when you want to visualize a series of if if else only put one breakpoint at the very
beginning and then we can use the step over button to step over each conditional you would never want
to press continue because that would just execute everything.
So let's just go ahead and press debug to start visualizing the runtime.
Temperature is 25.
That's really, really hot, 25 degrees Celsius.
So 25 is not less than or equal to negative one.
It's much warmer than that.
So we'll step over this condition because it evaluates the false.
This will not run.
Is 25 less than or equal to ten degrees Celsius?
No, it's much, much warmer than that.
So we'll step over this condition because it is also false, which defaults to the statement where the
forecast ends up equaling its warm go outside.
If I put another breakpoint over here and then press continue, you can see that the forecast gets updated
to it's warm, go outside and then we print that updated value.
Perfect test.
Case number two, you'll remember, is when the temperature equals negative one degrees Celsius.
So let's once again debug the runtime and clean up a little over here.
Try this again.
All right.
So temperature of a negative one.
That's fairly cold.
A temperature of negative one degrees Celsius does equal negative one satisfying this condition.
So the forecast is freezing.
Stay home.
That's what our forecast variable will get updated to press.
Continue here.
The forecast is freezing.
Stay home.
That's what we'll get printed.
All right.
We're doing great.
Test case number three is one and equals zero.
Let's visualize the runtime again.
Zero is not less than or equal to negative one.
It's warmer than not.
So we're going to step over this conditional because it's false.
But zero is less than or equal to ten.
So if we step over again, the forecast is chilly.
Wear a coat Now that we're done visualizing the chain of elseif and else we can press continue to continue
to the next breakpoint and it's going to print the updated forecast.
Test.
Case number four is when the temperature equals ten degrees.
Let's visualize the run time again.
Continue to the next breakpoint.
Now, you don't want to press continue again because you don't want to continue to the next breakpoint.
You want to step over this series of if else, if and else.
So let's do just that.
Ten is not less than or equal to negative one.
So we step over this false conditional.
A temperature of ten degrees Celsius is equal to ten.
So this conditional will be true, which means this LCF will get executed updating forecasts to its
Chile where a code.
Now we want to continue to the next breakpoint so we press continue.
After executing this line forecast was updated to its Chile where a code which we then end up printing.
All right.
Test.
Case number five is when the temperature equals 11.
Well, let's once again visualize the runtime when the temperature is 11 degrees.
Continue to the next breakpoint.
Now, we want to step over this series of if elseif and else 11 is not less than or equal to negative
one, it's not less than or equal to ten.
It's much warmer than that.
So we default to the WL statement where it's warm, go outside, continue to the next breakpoint.
That's what the forecast gets updated to and that's what we end up printing.
Test.
Case number six is -12 degrees Celsius.
Visualizing the runtime again.
-12 is less than or equal to negative one.
So we step over the forecast is freezing, stay home, continue to the next breakpoint.
Our forecast variable was updated at line number nine, but then at line number 16, we're printing
that updated variable and it prints the forecast is freezing.
Stay home.
I hope you enjoyed this breakpoint session.