Java Bootcamp – Workbooks and Challenges
)}

Workbook 4.2

Welcome to workbook 4.2.

From Java Bootcamp Resources -> Module 1 -> 4\. Functions, open Workbook 4.2.

Tip the waiter.


You enjoyed a luscious meal, and the waiter was wonderful.

The bill was $53.50. It's customary 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 type double.
/** * 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

Good Luck!

Feedback Summary
4.8
38 students
5

92%
4

3%
3

0%
2

0%
1

5%
Written Reviews
There are no written reviews yet.