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 Work Book 4.2.
We ate at a restaurant and our bill came to 53 bucks.
And what we need to do is create a function that when called tips the waiter 15% of the bill.
So what we'll do is we'll start with the familiar public static void void because you haven't learned
about return values yet, so our function will not return anything.
The function name is tip the waiter and the function takes in one parameter the bill.
This parameter expects to receive a double value whenever this function gets called.
And based on the bill value that gets provided, we need to calculate a tip.
A tip is 15% of the bill, so we'll say double tip is equal to bill times 0.15.
And then we print.
Your service was wonderful.
Please accept this tip.
The tip being whatever we just calculated.
And now we can call the function tip the waiter.
And that's all we're calling the function, passing in a double that equals $53.
The parameter is going to store the double value that gets passed in here we calculate a tip based on
the value that was passed in and then we print it.
Let us visualize the runtime using our trusty debugger.
So here we're calling the function passing in a value of $53.
Stepping inside the function, the parameter bill equals whatever value that was passed in $53 that
times 0.15 results in a tip of 8.0 to 5.
And here we're saying your service was wonderful.
Please accept this tip.
Person continue to resume runtime.
And that is all.
Let's say the bill was $75.
This time we're passing in an argument of 75.
I shouldn't have stepped over it.
Let me restart.
I'm going to step inside the function.
The parameter bill stores the value that was passed in it equals 75, 75, 15% of that equals 11.25.
Your service was wonderful.
Please accept this tip of $11.
Perfect.