1 00:00:00,790 --> 00:00:03,690 Okay, so we have the beginning of our menu set up. 2 00:00:03,690 --> 00:00:08,380 Let's go ahead and add another option to print out our contact list. 3 00:00:08,380 --> 00:00:13,360 Now, if we scroll down here, we already have this method called print_contact_list 4 00:00:13,360 --> 00:00:16,070 which does exactly what we want to. 5 00:00:16,070 --> 00:00:21,160 So, all we need to do is add this as a menu option. 6 00:00:22,480 --> 00:00:24,840 So we'll go ahead and add the option to print it out. 7 00:00:29,762 --> 00:00:30,400 There we go. 8 00:00:30,400 --> 00:00:32,040 That will just display it on the menu. 9 00:00:33,350 --> 00:00:35,460 Now we need to add this as an option. 10 00:00:36,920 --> 00:00:40,080 And this is really easy, all we need to do is say. 11 00:00:40,080 --> 00:00:45,237 When the input is the letter p, we call the print_contact_list method. 12 00:00:48,130 --> 00:00:49,760 Let's just make sure we spelled it correctly. 13 00:00:51,200 --> 00:00:52,360 And we did. 14 00:00:53,960 --> 00:00:56,839 So this should be everything that we need to do. 15 00:00:56,839 --> 00:00:59,520 Let's go ahead and run this and make sure it works. 16 00:01:02,800 --> 00:01:04,430 All right. Here are two options, 17 00:01:04,430 --> 00:01:07,130 p to print the address book, and e to exit. 18 00:01:07,130 --> 00:01:08,100 Well, let's go ahead and print it. 19 00:01:09,360 --> 00:01:13,490 Well, it prints the word Contact List, but nothing's in there. 20 00:01:13,490 --> 00:01:14,200 And why is that? 21 00:01:15,250 --> 00:01:17,860 It's because we haven't added any contacts. 22 00:01:18,970 --> 00:01:25,575 So, what we're gonna have to do is add the ability to add contacts in here. 23 00:01:28,457 --> 00:01:30,354 Now we're gonna do that in two parts here. 24 00:01:32,532 --> 00:01:36,130 So let's go ahead and add the ability to add a contact. 25 00:01:40,253 --> 00:01:42,280 And add a menu item for it. 26 00:01:44,690 --> 00:01:49,796 And we're just going to say when the input letter is a, 27 00:01:49,796 --> 00:01:56,358 we're gonna call the add contact method, which we have to write now. 28 00:02:01,550 --> 00:02:05,100 So this is gonna be similar to what we did before. 29 00:02:05,100 --> 00:02:09,030 And let's go ahead, and since we're adding a contact, 30 00:02:09,030 --> 00:02:12,600 which we're going to be appending to the internal contacts array, 31 00:02:13,860 --> 00:02:16,540 let's go ahead and initialize a new contact. 32 00:02:16,540 --> 00:02:22,100 And now we can just prompt the user to enter the information about their contact. 33 00:02:24,844 --> 00:02:28,476 Enter their first name, and 34 00:02:28,476 --> 00:02:33,022 then the same thing with last name. 35 00:02:38,782 --> 00:02:40,276 Oops, forgot the middle name here. 36 00:02:49,854 --> 00:02:51,630 Okay, that looks good. 37 00:02:51,630 --> 00:02:55,090 Now we're in an interesting position here because we could append the contact to 38 00:02:55,090 --> 00:03:00,060 the contacts array right now, but we still want to be able 39 00:03:00,060 --> 00:03:04,110 to enter addresses or phone numbers for each contact. 40 00:03:04,110 --> 00:03:06,240 Now we'll get to that in a minute, but for 41 00:03:06,240 --> 00:03:11,337 right now let's just append the contacts array. 42 00:03:11,337 --> 00:03:15,520 Now remember, we've got an attribute reader for the contacts array. 43 00:03:16,940 --> 00:03:19,320 So we don't have to use the at sign to append it. 44 00:03:20,870 --> 00:03:26,708 So we'll just say contacts.push and 45 00:03:26,708 --> 00:03:29,520 it will be this contact right here. 46 00:03:32,020 --> 00:03:36,410 So let's click down here and exit, all right, clear the screen, 47 00:03:36,410 --> 00:03:37,580 I'm gonna run this again. 48 00:03:38,620 --> 00:03:44,580 And see what happens so let me add a contact, Jason, no middle name, Seifer. 49 00:03:44,580 --> 00:03:48,120 Okay that seems to have worked, now let's go ahead and print the address book. 50 00:03:49,700 --> 00:03:56,755 Okay, looks like I'm in here, let me add another contact. 51 00:03:56,755 --> 00:04:00,760 Nick Avery Pettit. 52 00:04:00,760 --> 00:04:02,110 Okay, that seems to have worked. 53 00:04:03,260 --> 00:04:04,730 Let's go ahead and print the address book. 54 00:04:06,820 --> 00:04:09,240 Okay, looks like that's working. 55 00:04:10,360 --> 00:04:12,280 And let's just see something really quickly here. 56 00:04:12,280 --> 00:04:16,140 If we exit, and I'm gonna clear my screen, and if I restart again, 57 00:04:16,140 --> 00:04:18,150 if we go to print the address book, 58 00:04:18,150 --> 00:04:24,070 you'll notice that it's empty even though we just added Nick and Jason as contacts. 59 00:04:24,070 --> 00:04:28,900 The reason is, that takes place entirely in memory and we are gonna be writing this 60 00:04:28,900 --> 00:04:31,890 out to a file but we'll be doing that a little bit later. 61 00:04:31,890 --> 00:04:35,770 Next up we're gonna be going through and doing the loop for adding addresses and 62 00:04:35,770 --> 00:04:40,720 phone numbers to our contact before pinning them to the contact's array.