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:11,000 --> 00:00:12,500 Welcome to Workbook 4.4. 4 00:00:12,530 --> 00:00:15,440 Task one is to start by picking up the user's choice. 5 00:00:15,440 --> 00:00:21,320 We already have an INT variable here called choice, so here we can say choice is equal to scan dot 6 00:00:21,440 --> 00:00:22,490 next int. 7 00:00:23,910 --> 00:00:26,310 And pick up whatever integer they input. 8 00:00:27,000 --> 00:00:31,770 Task two is to write a function, so we'll say public static. 9 00:00:31,890 --> 00:00:35,910 The function is going to be void because there is no return type specified. 10 00:00:35,940 --> 00:00:38,190 The function is called draw. 11 00:00:39,160 --> 00:00:47,410 And it expects to receive an integer when called so int choice and inside the function body we need 12 00:00:47,410 --> 00:00:54,040 to draw either a butterfly, an elephant, a bear or a snake, depending on what the choice is. 13 00:00:54,040 --> 00:01:00,880 So we'll use a switch statement to compare the choice against a list of cases. 14 00:01:01,060 --> 00:01:06,580 In the event that it's case one, then we're going to print a butterfly. 15 00:01:08,940 --> 00:01:12,240 Let's copy and paste this a few more times. 16 00:01:15,310 --> 00:01:16,840 So if it's case one. 17 00:01:17,630 --> 00:01:21,590 Then we're going to use the following print statement to print our butterfly. 18 00:01:28,150 --> 00:01:29,770 Don't forget your brake keyword. 19 00:01:29,770 --> 00:01:35,860 If it's case two, then the user chose to draw an elephant. 20 00:01:44,530 --> 00:01:44,840 Okay. 21 00:01:45,070 --> 00:01:46,780 If it's case three. 22 00:01:48,430 --> 00:01:51,220 Then the user chose to draw. 23 00:01:53,090 --> 00:01:53,960 Teddy bear. 24 00:01:58,190 --> 00:01:59,350 The case for. 25 00:02:01,070 --> 00:02:02,450 They want to draw a snake. 26 00:02:13,850 --> 00:02:19,040 And now if they choose something that isn't one, two, three or four, then nothing is going to happen. 27 00:02:19,040 --> 00:02:21,500 Really, I don't feel like putting in any error messages. 28 00:02:21,500 --> 00:02:24,620 So you can keep the default statement, you can remove. 29 00:02:24,620 --> 00:02:26,060 It doesn't matter. 30 00:02:26,450 --> 00:02:33,800 And now we're down to task number three, where we call the draw function and pass in the user's choice. 31 00:02:33,800 --> 00:02:36,830 So we will call draw choice. 32 00:02:37,100 --> 00:02:38,090 And that is all. 33 00:02:40,030 --> 00:02:44,320 We can visualize the runtime starting from here. 34 00:02:50,560 --> 00:02:54,010 So I will choose to draw a bare. 35 00:02:54,810 --> 00:02:57,680 The next end function waits for me to enter an integer. 36 00:02:57,690 --> 00:03:02,460 I enter three, it picks it up, and then we set choice equal to the return value. 37 00:03:02,490 --> 00:03:07,800 Then we pass in a value of three into the draw function, as we call it. 38 00:03:07,800 --> 00:03:10,050 We'll step inside of the draw function. 39 00:03:12,900 --> 00:03:20,370 A choice of three will match the following case, in which case it's just going to draw a teddy bear. 40 00:03:23,840 --> 00:03:26,630 And then the break key word breaks the switch statement. 41 00:03:27,570 --> 00:03:29,860 Thus reaching the end of our function. 42 00:03:29,880 --> 00:03:33,540 And there you have it, a nice, cute little teddy bear. 43 00:03:33,660 --> 00:03:36,060 I hope you enjoyed this breakpoint session.