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 4.4.
Task one is to start by picking up the user's choice.
We already have an INT variable here called choice, so here we can say choice is equal to scan dot
next int.
And pick up whatever integer they input.
Task two is to write a function, so we'll say public static.
The function is going to be void because there is no return type specified.
The function is called draw.
And it expects to receive an integer when called so int choice and inside the function body we need
to draw either a butterfly, an elephant, a bear or a snake, depending on what the choice is.
So we'll use a switch statement to compare the choice against a list of cases.
In the event that it's case one, then we're going to print a butterfly.
Let's copy and paste this a few more times.
So if it's case one.
Then we're going to use the following print statement to print our butterfly.
Don't forget your brake keyword.
If it's case two, then the user chose to draw an elephant.
Okay.
If it's case three.
Then the user chose to draw.
Teddy bear.
The case for.
They want to draw a snake.
And now if they choose something that isn't one, two, three or four, then nothing is going to happen.
Really, I don't feel like putting in any error messages.
So you can keep the default statement, you can remove.
It doesn't matter.
And now we're down to task number three, where we call the draw function and pass in the user's choice.
So we will call draw choice.
And that is all.
We can visualize the runtime starting from here.
So I will choose to draw a bare.
The next end function waits for me to enter an integer.
I enter three, it picks it up, and then we set choice equal to the return value.
Then we pass in a value of three into the draw function, as we call it.
We'll step inside of the draw function.
A choice of three will match the following case, in which case it's just going to draw a teddy bear.
And then the break key word breaks the switch statement.
Thus reaching the end of our function.
And there you have it, a nice, cute little teddy bear.
I hope you enjoyed this breakpoint session.