1 00:00:00,150 --> 00:00:03,840 Before we start, did you try solving the workbook yourself? 2 00:00:03,870 --> 00:00:09,630 If not, please click the link in the resources folder and follow the instructions for this workbook. 3 00:00:10,840 --> 00:00:12,850 Welcome to Work Book 4.2. 4 00:00:12,880 --> 00:00:17,560 We ate at a restaurant and our bill came to 53 bucks. 5 00:00:17,560 --> 00:00:23,530 And what we need to do is create a function that when called tips the waiter 15% of the bill. 6 00:00:23,680 --> 00:00:30,730 So what we'll do is we'll start with the familiar public static void void because you haven't learned 7 00:00:30,730 --> 00:00:34,730 about return values yet, so our function will not return anything. 8 00:00:34,750 --> 00:00:40,990 The function name is tip the waiter and the function takes in one parameter the bill. 9 00:00:45,230 --> 00:00:50,330 This parameter expects to receive a double value whenever this function gets called. 10 00:00:50,630 --> 00:00:55,280 And based on the bill value that gets provided, we need to calculate a tip. 11 00:00:55,310 --> 00:01:05,090 A tip is 15% of the bill, so we'll say double tip is equal to bill times 0.15. 12 00:01:05,780 --> 00:01:07,040 And then we print. 13 00:01:08,260 --> 00:01:09,830 Your service was wonderful. 14 00:01:09,850 --> 00:01:11,950 Please accept this tip. 15 00:01:13,330 --> 00:01:16,570 The tip being whatever we just calculated. 16 00:01:18,810 --> 00:01:21,300 And now we can call the function tip the waiter. 17 00:01:26,670 --> 00:01:32,280 And that's all we're calling the function, passing in a double that equals $53. 18 00:01:33,440 --> 00:01:39,710 The parameter is going to store the double value that gets passed in here we calculate a tip based on 19 00:01:39,710 --> 00:01:42,320 the value that was passed in and then we print it. 20 00:01:42,320 --> 00:01:46,250 Let us visualize the runtime using our trusty debugger. 21 00:01:51,590 --> 00:01:55,880 So here we're calling the function passing in a value of $53. 22 00:01:56,450 --> 00:02:03,980 Stepping inside the function, the parameter bill equals whatever value that was passed in $53 that 23 00:02:03,980 --> 00:02:09,520 times 0.15 results in a tip of 8.0 to 5. 24 00:02:09,530 --> 00:02:11,900 And here we're saying your service was wonderful. 25 00:02:11,900 --> 00:02:14,030 Please accept this tip. 26 00:02:14,910 --> 00:02:17,220 Person continue to resume runtime. 27 00:02:17,220 --> 00:02:18,690 And that is all. 28 00:02:19,090 --> 00:02:21,600 Let's say the bill was $75. 29 00:02:25,460 --> 00:02:28,580 This time we're passing in an argument of 75. 30 00:02:30,140 --> 00:02:31,670 I shouldn't have stepped over it. 31 00:02:31,700 --> 00:02:33,050 Let me restart. 32 00:02:33,170 --> 00:02:34,880 I'm going to step inside the function. 33 00:02:35,880 --> 00:02:45,670 The parameter bill stores the value that was passed in it equals 75, 75, 15% of that equals 11.25. 34 00:02:45,690 --> 00:02:47,010 Your service was wonderful. 35 00:02:47,010 --> 00:02:50,190 Please accept this tip of $11. 36 00:02:51,170 --> 00:02:52,010 Perfect.