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,980 --> 00:00:12,570 Welcome to Work Book 4.3. 4 00:00:12,570 --> 00:00:15,090 Let us jump right into it. 5 00:00:15,120 --> 00:00:21,540 Task one is to make a function called Fahrenheit two Celsius that expects to receive a double value. 6 00:00:21,540 --> 00:00:27,210 And then from the value that it receives, it's going to return a Celsius result. 7 00:00:27,210 --> 00:00:30,930 So I will start by defining my function over here. 8 00:00:30,960 --> 00:00:32,460 Public static. 9 00:00:32,460 --> 00:00:38,700 The functions return type needs to be double because we expect to return a double value and the function 10 00:00:38,700 --> 00:00:40,860 name is Fahrenheit to Celsius. 11 00:00:40,860 --> 00:00:48,390 The function must define one parameter called Fahrenheit because ultimately we're going to be receiving 12 00:00:48,390 --> 00:00:52,320 a Fahrenheit temperature and then converting it to Celsius. 13 00:00:52,320 --> 00:00:53,370 How will we do that? 14 00:00:53,400 --> 00:00:56,580 We're going to do that using the formula that was provided. 15 00:00:56,580 --> 00:00:58,200 So we'll say return. 16 00:01:02,220 --> 00:01:07,440 Copying the following Replace F with the Fahrenheit temperature that gets passed in. 17 00:01:07,980 --> 00:01:08,850 And that is all. 18 00:01:08,850 --> 00:01:15,210 When this function gets called, it will receive a Fahrenheit value, and the result that we return 19 00:01:15,210 --> 00:01:19,860 will be the conversion from Fahrenheit to Celsius using the following formula. 20 00:01:22,720 --> 00:01:25,750 Let's call this function three separate times. 21 00:01:26,750 --> 00:01:29,640 One four, the temperature in Fahrenheit at midnight. 22 00:01:29,660 --> 00:01:33,170 One for the temperature in Fahrenheit and during the evening. 23 00:01:33,290 --> 00:01:35,150 And one during noon. 24 00:01:40,910 --> 00:01:41,360 All right. 25 00:01:41,360 --> 00:01:47,120 Let us step inside the function every time we call it first, we're calling it passing in a value of 26 00:01:47,120 --> 00:01:49,100 77 degrees Fahrenheit. 27 00:01:49,160 --> 00:01:54,590 If you step inside the function, the Fahrenheit parameter stores the value that was passed in. 28 00:01:54,590 --> 00:01:59,960 And here, using the value that was passed in, we can calculate what the corresponding Celsius temperature 29 00:01:59,960 --> 00:02:02,570 will be and return the final result. 30 00:02:04,080 --> 00:02:08,490 The function call retains the return value of 25 degrees. 31 00:02:09,000 --> 00:02:10,919 But we're not really doing anything with it. 32 00:02:10,919 --> 00:02:16,740 So moving on to the next breakpoint here, we're calling the function again, this time passing in a 33 00:02:16,740 --> 00:02:19,320 temperature of 61 degrees Fahrenheit. 34 00:02:20,040 --> 00:02:23,340 The parameter stores, the value that was passed in. 35 00:02:23,340 --> 00:02:29,310 And here, using the Fahrenheit temperature, we can calculate the corresponding Celsius temperature 36 00:02:29,310 --> 00:02:30,420 and return it. 37 00:02:30,420 --> 00:02:37,410 And the function call holds on to the return value of 16.11 degrees Celsius. 38 00:02:37,410 --> 00:02:43,950 We could store it in a variable, but right now let us just move on to task number two and stop the 39 00:02:43,960 --> 00:02:44,730 runtime. 40 00:02:45,060 --> 00:02:49,890 Okay, So we've successfully defined our Fahrenheit to Celsius function. 41 00:02:50,430 --> 00:02:51,750 That's it for task one. 42 00:02:52,020 --> 00:02:56,700 Task number two is to make a function that prints all of the temperatures. 43 00:02:56,700 --> 00:03:01,200 It's going to need to receive a Fahrenheit temperature and it will not return anything. 44 00:03:01,200 --> 00:03:05,190 So right there, we know that it's going to be void, public static void. 45 00:03:05,190 --> 00:03:10,410 The function will not return anything because all it will do is print a bunch of temperatures. 46 00:03:10,410 --> 00:03:13,320 It's going to receive the Fahrenheit temperature. 47 00:03:14,900 --> 00:03:19,580 And upon receiving a Fahrenheit value, the first thing that we're going to do is print it. 48 00:03:19,580 --> 00:03:23,330 So we'll say the value in Fahrenheit equals. 49 00:03:25,640 --> 00:03:27,380 Whatever value that was passed in. 50 00:03:28,240 --> 00:03:33,430 And the second print statement is going to calculate the corresponding Celsius temperature. 51 00:03:37,430 --> 00:03:44,690 So here what we can do is call Fahrenheit to Celsius, and then at the end we will print a new line. 52 00:03:45,350 --> 00:03:49,580 So what this line is doing is printing a double value. 53 00:03:49,580 --> 00:03:55,850 And what this line is doing is printing whatever double value gets returned when we call Fahrenheit 54 00:03:55,880 --> 00:03:57,020 to Celsius. 55 00:03:58,340 --> 00:03:59,300 All right. 56 00:03:59,450 --> 00:04:03,320 Now, what I'm going to do is call print temperatures. 57 00:04:07,180 --> 00:04:08,890 And now we can visualize the runtime. 58 00:04:11,460 --> 00:04:16,829 So here we're calling print temperatures, passing in a temperature of 77 degrees Fahrenheit. 59 00:04:16,860 --> 00:04:20,490 Here we're just printing the Fahrenheit value that was passed in. 60 00:04:21,029 --> 00:04:22,830 And here we're calling to functions. 61 00:04:22,830 --> 00:04:26,870 We're calling the print line function, and we're calling Fahrenheit to Celsius. 62 00:04:26,880 --> 00:04:31,020 So the first step into is going to take you to some random class. 63 00:04:31,020 --> 00:04:32,820 We'll step out of it. 64 00:04:32,820 --> 00:04:38,970 And then the next step into is going to step inside of our second function call Fahrenheit to Celsius. 65 00:04:38,970 --> 00:04:44,730 And based on the value that was passed in, we're calculating the corresponding Celsius temperature 66 00:04:44,730 --> 00:04:47,040 and we're returning the final result. 67 00:04:47,070 --> 00:04:50,340 The function call basically equals the return value. 68 00:04:50,370 --> 00:04:55,710 It equals the final result of 25 degrees Celsius, which we are then printing. 69 00:04:57,720 --> 00:04:58,260 All right. 70 00:04:58,260 --> 00:05:00,330 Continuing to the next breakpoint here. 71 00:05:00,330 --> 00:05:02,180 We're calling the function a second time. 72 00:05:02,190 --> 00:05:05,610 This time we're passing in a value of 61 degrees Fahrenheit. 73 00:05:05,910 --> 00:05:08,550 Here we're just printing the value that was passed in. 74 00:05:08,550 --> 00:05:12,270 But then here we're printing whatever, Fahrenheit to Celsius returns. 75 00:05:12,270 --> 00:05:16,590 In this case, it's going to return 16.21 degrees Celsius. 76 00:05:16,620 --> 00:05:22,260 Now, I'm just going to continue to the next breakpoint, keep pressing, continue this time calling 77 00:05:22,260 --> 00:05:26,300 print temperatures for a Fahrenheit value of 55 degrees. 78 00:05:26,310 --> 00:05:30,870 In this case, it's going to rent a Celsius value of 12.7 degrees. 79 00:05:31,230 --> 00:05:31,830 That is all. 80 00:05:31,830 --> 00:05:34,380 I hope you enjoyed this breakpoint session.