Workbook 4.2
From the Java Bootcamp Resources
, launch the Workbook 4.2
folder.
Tip the waiter.
Your bill was $53.50. It's polite to tip the waiter 15% of your bill.
Task 1 - Write a function
You will write a function that does this task.
- Function name:
tipTheWaiter
. It calculates a tip and prints it.
/** * Function name: tipTheWaiter - calculates a tip and prints it. <----- * @param bill (double). * * Inside the function: * 1. Calculates a tip that's 15 percent of the bill you paid. * 2. Prints: your service was wonderful! Please, accept this tip: $<tip> * */
- Parameters: The function takes one parameter named
bill
of typedouble
.
/** * Function name: tipTheWaiter - calculates a tip and prints it. * @param bill (double). <----- * * Inside the function: * 1. Calculates a tip that's 15 percent of the bill you paid. * 2. Prints: your service was wonderful! Please, accept this tip: $<tip> * */
-
Return value: the comment says nothing about a return value. So, you can assume the function is
void
. -
Inside the function, implement the following logic:
/** * Function name: tipTheWaiter - calculates a tip and prints it. * @param bill (double). * * Inside the function: <----- * 1. Calculates a tip that's 15 percent of the bill you paid. * 2. Prints: your service was wonderful! Please, accept this tip: $<tip> * */
Task 2 - Call the function
Call the function from main()
.
Run your code.
Waiter: I hope you enjoyed your meal!
Thank you!
Your service was wonderful! Please, accept this tip: $8.025
Visualizing the Runtime
After you solve this workbook, I still recommend watching the video solution on Udemy.
It will show you how to visualize the runtime using Visual Studio Code.
Associated Course: The Complete Java Development Bootcamp
Related Course: The Complete Spring Boot Development Bootcamp – Become a Java Web Developer
Feedback Summary
4.7
43 students
5
91%
4
2%
3
0%
2
0%
1
7%
Written Reviews
There are no written reviews yet.