This video present the solution to workbook 3.7.
Task number one is to pick up the user's decision.
So here we can say string decision is equal to skin dot next line and if the decision equals yes.
So if decision dot equals the string.
Yes.
Then we're going to dump all of this code inside of this if statement.
If they are here to get a mortgage, then we will execute all of the code that is involved in granting
them a mortgage.
Otherwise, else we will print OC.
Have a nice day.
Okay.
So that was task number two for you.
Let's go ahead and visualize the runtime.
I'm only going to put breakpoints here.
We only need one breakpoint to remember to visualize F and L statements.
And that should be good.
We'll debug the runtime.
So here it's asking me if I want to get a mortgage, if I execute this line of code scanned.
Next line is going to wait for me to enter any string value.
And that's exactly what it does.
I'm going to enter a decision of either yes or no.
In this case, Yes, if I want this to execute.
All right.
The decision variable equals.
Yes.
So this is going to evaluate to true.
Remember, do not press continue, continue continues to the next breakpoint, since there are no other
breakpoints, it's just going to resume execution of our code until the application completes normally.
So we're going to step over this conditional.
And we can visualize what happens inside of it line by line, by stepping over each line.
Right now, it just prints a bunch of messages.
So we need to write all of the relevant code in the event that the user wants to get a mortgage.
Now let us restart the runtime.
By pressing continue scan.
The next line waits for me to enter any value.
I'm going to enter.
No, no does not equal yes.
So this will evaluate the false.
If I press step over, it goes to the LL statement and it prints.
Okay.
Have a nice day.
Now I can press continue to resume program execution.
Prince.
Okay.
Have a nice day.
All right, Let us finish writing the code here.
We will say double savings is equal to skin.
Next double to pick up how much money they have in their savings account.
And double debt is equal to skin.
Next double once again.
How many years have you worked for?
That seems like a whole number to me.
End years is equal to skin.
Next int.
What is your name?
String name is equal to skin.
Next line.
But remember when next line comes after a next end, next double or a next, we need to put in a throwaway
next line.
Right before the quote unquote, real next line, the one that actually matters.
So this one is going to get skipped.
This one is going to get wasted while this one actually waits for the user to enter in a string, which
will then get stored in a name variable.
All right.
Now, we want to approve the mortgage if they meet the requirements that were specified in the article.
So you'll remember the requirements for them to be approved for a mortgage are if their savings are
at least 10,000.
So if their savings are greater than or equal to $10,000.
And they need to also have less than $5,000 in debt.
So the debt also has to be less than 5000.
And they need more than two years of work experience.
So end.
Years has to be more than two.
If the user meets all of these requirements, then we can approve them for a mortgage.
We can say congratulations, whoever, whatever their name ends up being.
Congratulations name you have been approved else.
Sorry.
You are not eligible for a mortgage.
And that song.
Let us visualize the runtime.
By pressing continue, it's going to execute this line of code.
And next line here waits for me to enter in a string.
I'm going to enter.
Yes.
The decision yes equals the string.
Yes.
So this will evaluate to true executing the if statement.
Remember not to press continue because continue continues to the next breakpoint, but there are no
other breakpoints.
So it's just going to resume execution of our program until it completes naturally.
So we will step over this conditional and step over every single line inside of it.
Great.
In one line, how much money do you have in your savings?
You will step over this line, Keep stepping over.
Now I need to input my savings and debt in one line.
So if I say 20,000.
Followed by 2000.
This scandal.
Next double is going to scan for the first double value that we input.
And this scandal next double will skin for the next double separated by white space.
Let's test this out.
And beautiful.
Just as I predicted, this one picked up this value, and after stepping over this one, it scanned
for the next double.
That was the limited by a white space.
So now this variable stores the value 20,000.
That's variable stores of the value 2000.
How many years have you worked for?
We're going to put three years so that we're approved for the mortgage.
What is your name?
Because this scan next line comes after a next int, it's going to get skipped.
So as I stepped over it, it did not actually prompt me to enter anything.
But if I step over this skin next line, it's actually going to wait for me so that it can scan for
a string value.
So I will enter in a name of Tim.
Scanned up next line picks up our string value, and that string value gets stored in a string variable
name.
And now in this conditional, it's checking if my savings is greater than or equal to 10,000.
If debt is smaller than 5000, and if the number of years worked is over.
Two.
It's really beautiful that I can see my values side by side.
20,000 is greater than or equal to 10,000.
My debt is smaller than 5000 and I have worked for more than two years.
So this expression is going to evaluate to true and running the code inside.
Congratulations, Tim.
You have been approved.
All right, Now, what if I do not meet the requirements?
Let's try this out again.
The press continue to continue to the next breakpoint.
Are you here to get a mortgage?
We'll say yes.
Yes equals yes.
This this evaluates to true will step over.
We'll put in a savings of, let's say, 5000, which is less than 10,000 and a debt of 2000.
So scanned.
Our next double picks up the first double that we input.
And after I step over this line it will scan for the next double.
That's the limited by white space, picking it up, storing it in a depth variable.
How many years have you worked for?
Will print this after stepping over the next end, it's going to prompt me to enter an integer.
I'm going to say three years.
What is your name?
This next line is going to get skipped.
It will get wasted because it comes after a next int.
This next line will actually prompt me to enter in a string.
We will say once again, Tim.
Submitting it to him gets picked up and then stored in a name string.
And now, conveniently, I can visualize my variables right beside the conditions.
So the debt is smaller than 5000.
This one is good.
The years is bigger than two.
This one is good.
However, the savings is not greater than or equal to 10,000 because we're using the end logical operator.
All of these need to be true for the whole expression to be true, but because one of them is false,
this entire expression is going to be false.
The if statement will not run.
And what's actually going to run is the LL statements.
All right.
Sorry.
You are not eligible for a mortgage.
You did not meet all the requirements and now I can press continue so that execution can resume and
the program will terminate naturally.
All right.
That is all.
I really hope you enjoyed these breakpoint sessions.
The one thing I really wanted to drive home was how easy it is to visualize.
And if else, all you have to do is put one breakpoint in the beginning and then keep pressing.
Step over.
But if you just want to navigate from one breakpoint to another, then you can press the button.
Continue.
All right.
That is all.