1 00:00:00,390 --> 00:00:02,700 How did it go with the second challenge? 2 00:00:02,700 --> 00:00:04,690 Let's walk through my solution. 3 00:00:04,690 --> 00:00:08,468 In the album class, I stubbed out the loan and return methods. 4 00:00:08,468 --> 00:00:16,135 Public void Loan() And public void Return() 5 00:00:23,478 --> 00:00:26,953 Since the methods won't be returning a value to the caller, 6 00:00:26,953 --> 00:00:30,303 I use the special keyword void for the method return type. 7 00:00:32,890 --> 00:00:38,150 To complete the loan method, I added a string parameter named loanee. 8 00:00:39,360 --> 00:00:42,030 Defining this parameter will allow the caller 9 00:00:42,030 --> 00:00:45,470 to provide the name of the person who's borrowing the item. 10 00:00:45,470 --> 00:00:49,722 At this point, I remembered that I needed to add two new fields to the album class. 11 00:00:52,150 --> 00:01:01,430 A string field named Loanee And a bool field namedOnLoan. 12 00:01:05,262 --> 00:01:07,229 And then, back in the Loan method, 13 00:01:07,229 --> 00:01:10,187 I set the loanee field to the loanee parameter value. 14 00:01:15,840 --> 00:01:20,957 And the OnLoan field to true to indicate that the item is currently on loan. 15 00:01:24,409 --> 00:01:26,091 To complete the return method, 16 00:01:26,091 --> 00:01:29,680 I reset the loan-related fields to their default values. 17 00:01:29,680 --> 00:01:35,962 Null for the Loanee field And false for the OnLoan field. 18 00:01:37,813 --> 00:01:41,251 To indicate that the item was returned to the media library. 19 00:01:45,786 --> 00:01:50,920 A quick note about the default values for the Loanee, and OnLoan fields. 20 00:01:50,920 --> 00:01:52,960 The default values for these fields work for 21 00:01:52,960 --> 00:01:57,940 our needs when an item is initially created and added to the media library. 22 00:01:57,940 --> 00:02:00,350 It shouldn't have a Loanee field value. 23 00:02:00,350 --> 00:02:04,950 And the OnLoan field should be set to false, given that we 24 00:02:04,950 --> 00:02:09,420 don't need to initialize these fields to something other than their default values. 25 00:02:09,420 --> 00:02:14,420 Stylistically, you could explicitly set them to their default values. 26 00:02:14,420 --> 00:02:17,523 Doing that might make your intentions clearer 27 00:02:17,523 --> 00:02:20,312 to anyone else who's reading your code. 28 00:02:24,612 --> 00:02:29,362 If you like, you can set explicit default values here where the fields are defined. 29 00:02:29,362 --> 00:02:32,026 Or you can do that in the constructor. 30 00:02:32,026 --> 00:02:35,908 But for now, I'm just going to let the default values to be set implicitly. 31 00:02:40,368 --> 00:02:41,863 Continuing on. 32 00:02:41,863 --> 00:02:43,785 In the GetDisplayText method, 33 00:02:43,785 --> 00:02:48,137 I updated it to include the loan related fields if the item is out on loan. 34 00:02:53,368 --> 00:02:57,463 I started with declaring a string variable named text. 35 00:03:00,172 --> 00:03:05,340 For the text to return instead of immediately returning it from the method. 36 00:03:05,340 --> 00:03:09,140 Then, I added an if statement in order to check if the OnLoan field 37 00:03:09,140 --> 00:03:10,490 is set to a value of true. 38 00:03:11,910 --> 00:03:16,124 If OnLoan, then a set of curly braces. 39 00:03:17,316 --> 00:03:23,045 And if the OnLoan field value evaluates to true, 40 00:03:23,045 --> 00:03:29,474 I appended the following text onto the text variable, 41 00:03:29,474 --> 00:03:34,102 text = text + " (Currently on loan to 42 00:03:36,596 --> 00:03:42,370 Loanee, And then a close parenthesis. 43 00:03:42,370 --> 00:03:45,105 You could also use the addition assignment operator here. 44 00:03:49,431 --> 00:03:54,010 This operator says add the text variable to this string value, and 45 00:03:54,010 --> 00:03:58,110 assign the result back to the text variable. 46 00:03:58,110 --> 00:04:01,900 You'll see this approach used frequently when a string needs to be appended 47 00:04:01,900 --> 00:04:02,740 to another string. 48 00:04:04,310 --> 00:04:06,838 And don't forget to return the text variable. 49 00:04:09,647 --> 00:04:14,434 To test my changes, I updated the Program.cs file to call the loan and 50 00:04:14,434 --> 00:04:15,660 return methods. 51 00:04:17,900 --> 00:04:21,617 Let's first write the media type information to the console, 52 00:04:21,617 --> 00:04:23,446 then loan out the first album. 53 00:04:26,916 --> 00:04:30,470 Remember, we need to pass the name of the loanee to the method call. 54 00:04:30,470 --> 00:04:32,557 How about Joe Smith? 55 00:04:34,189 --> 00:04:36,812 Then, let's write the media type information for 56 00:04:36,812 --> 00:04:38,400 album1 to the console again. 57 00:04:39,710 --> 00:04:42,320 And then, let's return the album. 58 00:04:42,320 --> 00:04:44,676 Album1 Return. 59 00:04:46,395 --> 00:04:48,020 And one more time. 60 00:04:48,020 --> 00:04:51,780 We'll write the media type information for the album to the console. 61 00:04:51,780 --> 00:04:54,478 And lastly, I compiled and ran the program. 62 00:04:59,940 --> 00:05:04,020 Here, we can see the display text before the item was loaned out. 63 00:05:05,160 --> 00:05:07,481 And then, when the item was loaned to Joe Smith. 64 00:05:09,950 --> 00:05:13,060 And here's the display text after the item was returned. 65 00:05:14,250 --> 00:05:17,510 Looks like everything is working as expected. 66 00:05:17,510 --> 00:05:18,740 For the third and 67 00:05:18,740 --> 00:05:22,540 last challenge in this practice session, let's make it possible to indicate that 68 00:05:22,540 --> 00:05:26,670 something is on loan without having to supply the loanee's name. 69 00:05:26,670 --> 00:05:30,860 To do this, you'll add a method overload for the loan method. 70 00:05:30,860 --> 00:05:33,780 The current method accepts a Loanee parameter, so 71 00:05:33,780 --> 00:05:39,030 you'll add a method overload with a loan method that doesn't accept any parameters. 72 00:05:39,030 --> 00:05:42,610 Also, update the GetDisplayText() method to account for 73 00:05:42,610 --> 00:05:45,280 when the Loanee field doesn't have a value. 74 00:05:45,280 --> 00:05:47,250 And that's it for the third challenge. 75 00:05:47,250 --> 00:05:48,110 We'll see you in a bit.