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.
Welcome to Workbook 5.9.
Task one is to prompt the user to enter their username and password.
So here we're going to say string, user name entry, whatever they enter is equal to skin next line.
And then string password entry.
Is equal to the password they enter.
And then task two is to set up a loop that keeps running while the username or password they input is
incorrect.
So while the username that they enter does not equal the actual username.
Or if the password is incorrect, if password entry does not equal the actual password.
Then we need to keep running this while loop and keep re prompting them to enter correct credentials.
So here we have to say.
System.out.println.
I don't know.
What was the actual message here?
Incorrect.
Please try again.
Seems there's a line of space before and a line of space after.
So incorrect.
Please try again.
Giving them the chance to update their username.
And their password.
And actually, I think the input looks a bit different.
Don't forget your print statements because they need to enter their username beside a prompt of username,
their password beside a prompt of password.
And I think now we should be good.
Do we print anything after it's successful?
So if they guess it right, that means the loop broke, in which case we print.
I don't know.
You can print anything you want.
We'll say success.
All right, Time to visualize the runtime.
So if I guess wrong, I'll say Ryan.
Password?
I don't know.
Items.
One, two, three.
So if we look here, the username entry is Ryan.
The actual username is Samantha.
The password entry is Adam's.
One, two, three.
The actual password is I love Java.
This evaluates to true because the user names don't equal each other.
This evaluates a true because the passwords don't equal each other.
So this entire thing will be true, prompting us to enter our username again.
So here I'll actually input the correct username.
Samantha.
But I will put in the incorrect password.
I will put in a password of I don't know.
I will put in the same incorrect password of one, two, three.
So while the username entry does equal the username, this is going to evaluate to false.
However, the password entry does not match the actual password.
This evaluates to true because we're using the or operator.
This whole thing is going to become true.
We entered incorrect credentials prompting us to try again.
This time I will put in a correct username of Samantha.
I will put in the correct password of I love Java.
All right, moving on.
This time this evaluates the faults because they do equal this evaluates the false as well, because
the passwords do equal, because this whole thing evaluated the false, the while loop breaks.
And it prints success.