1 00:00:00,340 --> 00:00:03,040 OK, so with our address class all set up, 2 00:00:03,040 --> 00:00:07,150 we can now make our contacts have many addresses. 3 00:00:07,150 --> 00:00:10,730 So just like before, we're going to need to require the address class. 4 00:00:12,800 --> 00:00:16,790 And now we can add an attribute reader for addresses as well. 5 00:00:21,610 --> 00:00:23,321 And then, once again, 6 00:00:23,321 --> 00:00:28,639 we need to set this to an empty array when we initialize the contact class. 7 00:00:31,199 --> 00:00:34,215 So we have our add phone number method. 8 00:00:34,215 --> 00:00:37,375 Our add address method is going to be very similar. 9 00:00:39,477 --> 00:00:44,351 We're gonna take the attributes of the address and 10 00:00:44,351 --> 00:00:49,222 do kind street_1, street_2, city, state, 11 00:00:49,222 --> 00:00:54,547 postal code, and then we will initialize a new instance 12 00:00:54,547 --> 00:01:00,019 of the address class like we did with phone number above. 13 00:01:05,119 --> 00:01:09,499 And now we can set all of the attributes to the arguments to this method. 14 00:01:28,599 --> 00:01:30,225 And then just like before, 15 00:01:30,225 --> 00:01:33,698 we want to append this to the internal array of addresses. 16 00:01:40,058 --> 00:01:43,384 And since addresses is an attribute reader, 17 00:01:43,384 --> 00:01:48,558 we don't have to use the at sign to address it as an instance variable. 18 00:01:52,718 --> 00:01:56,740 And so now the last thing that we will do here is we can print out phone numbers. 19 00:01:56,740 --> 00:01:59,019 Let's go ahead and print addresses as well. 20 00:02:05,479 --> 00:02:10,159 And this will print out the contact addresses. 21 00:02:10,159 --> 00:02:11,810 We'll say addresses. 22 00:02:11,810 --> 00:02:14,150 Again this is referencing the instance variable, 23 00:02:14,150 --> 00:02:15,930 which we have an attribute reader for. 24 00:02:17,420 --> 00:02:21,930 And for each one of those, we'll print out the address 25 00:02:23,570 --> 00:02:27,380 as a string, and we'll use the short version. 26 00:02:31,550 --> 00:02:32,790 So once we have that. 27 00:02:35,080 --> 00:02:41,190 We'll use our test and add an address. 28 00:02:41,190 --> 00:02:42,290 Home, 123 Main Street. 29 00:02:43,460 --> 00:02:45,520 There's no line two of that street. 30 00:02:48,035 --> 00:02:49,135 And that's in Portland. 31 00:02:51,545 --> 00:02:53,345 With that zip code. 32 00:02:53,345 --> 00:02:57,202 So, we've got the add_address method being called, sending an address and 33 00:02:57,202 --> 00:02:59,864 let's go ahead and print out the addresses as well. 34 00:03:04,723 --> 00:03:08,363 Now let's go ahead and run this contact file and see what happens. 35 00:03:10,363 --> 00:03:11,320 Okay. 36 00:03:11,320 --> 00:03:12,500 Here's Jason Seifer. 37 00:03:12,500 --> 00:03:15,835 Here's the phone numbers and here's the addresses. 38 00:03:15,835 --> 00:03:17,330 But what is all this? 39 00:03:18,400 --> 00:03:21,900 This is what was in the address file. 40 00:03:21,900 --> 00:03:24,290 This code is getting run 41 00:03:24,290 --> 00:03:29,180 when we require it up here on line two of our contact file. 42 00:03:29,180 --> 00:03:36,270 So now that we know this works, we can get this out of here and save that. 43 00:03:37,320 --> 00:03:43,510 Then clear my screen and run this again and this works just like we expect it to.