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:13,720 This video will present the solution to workbook 3.4. 4 00:00:13,750 --> 00:00:16,850 Once again, we're going to visualize the runtime using VS code. 5 00:00:16,870 --> 00:00:17,750 You know the drill. 6 00:00:17,770 --> 00:00:21,670 Make sure that you launch the exact folder that contains your java file. 7 00:00:21,700 --> 00:00:24,430 If you want to be able to visualize the runtime. 8 00:00:24,580 --> 00:00:25,450 All right. 9 00:00:25,450 --> 00:00:29,980 The workbook starts with a temperature in Celsius, 25 degrees Celsius. 10 00:00:29,980 --> 00:00:35,230 And there's also a string variable forecast that equals an empty string, which makes sense because 11 00:00:35,230 --> 00:00:41,380 we need to update this variable to a forecast based on the current temperature. 12 00:00:41,560 --> 00:00:43,960 So first, we're going to say if. 13 00:00:45,150 --> 00:00:53,300 The temperature is smaller than or equal to negative one degree Celsius and the forecast is freezing. 14 00:00:53,310 --> 00:00:54,210 Stay home. 15 00:01:02,580 --> 00:01:07,890 If this condition fails, that means the temperature is higher than negative one degrees Celsius. 16 00:01:07,890 --> 00:01:15,120 So in the next condition else, if we're going to check if the temperature is less than or equal to 17 00:01:15,120 --> 00:01:15,630 ten. 18 00:01:17,070 --> 00:01:20,700 If that's the case, then the forecast is chilly. 19 00:01:20,700 --> 00:01:22,590 Wear a coat. 20 00:01:26,830 --> 00:01:32,330 But if this condition is also false, that means the temperature is actually higher than ten. 21 00:01:32,350 --> 00:01:35,650 So in that case, we can say otherwise else. 22 00:01:36,400 --> 00:01:38,610 The forecast is warm. 23 00:01:38,620 --> 00:01:40,240 Go outside. 24 00:01:44,550 --> 00:01:45,450 All right. 25 00:01:45,690 --> 00:01:52,710 And depending on which condition executes, forecast is going to equal one of these values. 26 00:01:52,710 --> 00:01:54,720 And then we're printing the forecast. 27 00:01:54,750 --> 00:01:56,310 Let's visualize the runtime. 28 00:01:56,310 --> 00:02:00,910 So test case number one is when the temperature equals 25. 29 00:02:00,930 --> 00:02:04,500 We're going to put breakpoints here, here. 30 00:02:04,500 --> 00:02:11,550 And remember, when you want to visualize a series of if if else only put one breakpoint at the very 31 00:02:11,550 --> 00:02:18,210 beginning and then we can use the step over button to step over each conditional you would never want 32 00:02:18,210 --> 00:02:21,600 to press continue because that would just execute everything. 33 00:02:21,600 --> 00:02:27,090 So let's just go ahead and press debug to start visualizing the runtime. 34 00:02:28,490 --> 00:02:29,790 Temperature is 25. 35 00:02:29,810 --> 00:02:32,720 That's really, really hot, 25 degrees Celsius. 36 00:02:32,840 --> 00:02:36,680 So 25 is not less than or equal to negative one. 37 00:02:36,680 --> 00:02:38,570 It's much warmer than that. 38 00:02:47,250 --> 00:02:50,740 So we'll step over this condition because it evaluates the false. 39 00:02:50,760 --> 00:02:52,230 This will not run. 40 00:02:53,190 --> 00:02:56,550 Is 25 less than or equal to ten degrees Celsius? 41 00:02:56,580 --> 00:02:58,980 No, it's much, much warmer than that. 42 00:02:58,990 --> 00:03:05,340 So we'll step over this condition because it is also false, which defaults to the statement where the 43 00:03:05,340 --> 00:03:09,240 forecast ends up equaling its warm go outside. 44 00:03:09,270 --> 00:03:16,020 If I put another breakpoint over here and then press continue, you can see that the forecast gets updated 45 00:03:16,020 --> 00:03:21,180 to it's warm, go outside and then we print that updated value. 46 00:03:21,210 --> 00:03:22,560 Perfect test. 47 00:03:22,560 --> 00:03:27,510 Case number two, you'll remember, is when the temperature equals negative one degrees Celsius. 48 00:03:27,510 --> 00:03:32,610 So let's once again debug the runtime and clean up a little over here. 49 00:03:34,090 --> 00:03:35,380 Try this again. 50 00:03:37,050 --> 00:03:37,530 All right. 51 00:03:37,530 --> 00:03:40,440 So temperature of a negative one. 52 00:03:40,770 --> 00:03:42,180 That's fairly cold. 53 00:03:42,180 --> 00:03:48,330 A temperature of negative one degrees Celsius does equal negative one satisfying this condition. 54 00:03:48,330 --> 00:03:51,090 So the forecast is freezing. 55 00:03:51,090 --> 00:03:51,900 Stay home. 56 00:03:51,900 --> 00:03:55,140 That's what our forecast variable will get updated to press. 57 00:03:55,140 --> 00:03:56,250 Continue here. 58 00:03:57,400 --> 00:03:58,750 The forecast is freezing. 59 00:03:58,750 --> 00:03:59,410 Stay home. 60 00:03:59,410 --> 00:04:01,030 That's what we'll get printed. 61 00:04:01,360 --> 00:04:02,140 All right. 62 00:04:02,140 --> 00:04:03,550 We're doing great. 63 00:04:03,580 --> 00:04:06,700 Test case number three is one and equals zero. 64 00:04:06,730 --> 00:04:08,920 Let's visualize the runtime again. 65 00:04:11,350 --> 00:04:13,870 Zero is not less than or equal to negative one. 66 00:04:13,870 --> 00:04:15,430 It's warmer than not. 67 00:04:15,430 --> 00:04:19,450 So we're going to step over this conditional because it's false. 68 00:04:19,540 --> 00:04:22,420 But zero is less than or equal to ten. 69 00:04:22,420 --> 00:04:26,890 So if we step over again, the forecast is chilly. 70 00:04:26,890 --> 00:04:35,440 Wear a coat Now that we're done visualizing the chain of elseif and else we can press continue to continue 71 00:04:35,440 --> 00:04:39,760 to the next breakpoint and it's going to print the updated forecast. 72 00:04:41,390 --> 00:04:41,690 Test. 73 00:04:41,690 --> 00:04:45,680 Case number four is when the temperature equals ten degrees. 74 00:04:45,710 --> 00:04:47,870 Let's visualize the run time again. 75 00:04:48,530 --> 00:04:50,240 Continue to the next breakpoint. 76 00:04:50,240 --> 00:04:52,040 Continue to the next breakpoint. 77 00:04:52,070 --> 00:04:57,080 Now, you don't want to press continue again because you don't want to continue to the next breakpoint. 78 00:04:57,110 --> 00:05:01,010 You want to step over this series of if else, if and else. 79 00:05:01,010 --> 00:05:02,730 So let's do just that. 80 00:05:02,750 --> 00:05:05,870 Ten is not less than or equal to negative one. 81 00:05:05,870 --> 00:05:08,630 So we step over this false conditional. 82 00:05:09,110 --> 00:05:12,560 A temperature of ten degrees Celsius is equal to ten. 83 00:05:12,560 --> 00:05:20,720 So this conditional will be true, which means this LCF will get executed updating forecasts to its 84 00:05:20,720 --> 00:05:22,010 Chile where a code. 85 00:05:22,040 --> 00:05:25,550 Now we want to continue to the next breakpoint so we press continue. 86 00:05:26,030 --> 00:05:33,410 After executing this line forecast was updated to its Chile where a code which we then end up printing. 87 00:05:34,010 --> 00:05:35,060 All right. 88 00:05:36,390 --> 00:05:36,630 Test. 89 00:05:36,630 --> 00:05:39,780 Case number five is when the temperature equals 11. 90 00:05:40,650 --> 00:05:46,920 Well, let's once again visualize the runtime when the temperature is 11 degrees. 91 00:05:47,830 --> 00:05:49,630 Continue to the next breakpoint. 92 00:05:49,630 --> 00:05:51,590 Continue to the next breakpoint. 93 00:05:51,650 --> 00:05:57,490 Now, we want to step over this series of if elseif and else 11 is not less than or equal to negative 94 00:05:57,490 --> 00:06:00,400 one, it's not less than or equal to ten. 95 00:06:00,400 --> 00:06:01,870 It's much warmer than that. 96 00:06:01,870 --> 00:06:08,230 So we default to the WL statement where it's warm, go outside, continue to the next breakpoint. 97 00:06:08,230 --> 00:06:12,730 That's what the forecast gets updated to and that's what we end up printing. 98 00:06:13,630 --> 00:06:13,900 Test. 99 00:06:13,900 --> 00:06:17,980 Case number six is -12 degrees Celsius. 100 00:06:18,190 --> 00:06:20,260 Visualizing the runtime again. 101 00:06:21,850 --> 00:06:25,150 -12 is less than or equal to negative one. 102 00:06:25,150 --> 00:06:31,660 So we step over the forecast is freezing, stay home, continue to the next breakpoint. 103 00:06:31,660 --> 00:06:37,990 Our forecast variable was updated at line number nine, but then at line number 16, we're printing 104 00:06:37,990 --> 00:06:42,460 that updated variable and it prints the forecast is freezing. 105 00:06:42,460 --> 00:06:43,510 Stay home. 106 00:06:44,110 --> 00:06:46,750 I hope you enjoyed this breakpoint session.