1 00:00:00,210 --> 00:00:03,870 Before we start, did you try solving the workbook yourself? 2 00:00:03,900 --> 00:00:09,660 If not, please click the link in the resources folder and follow the instructions for this workbook. 3 00:00:10,910 --> 00:00:12,750 Welcome to Workbook 7.2. 4 00:00:12,770 --> 00:00:18,350 The way we have it right now is as soon as we create an object of the person class, then we update 5 00:00:18,350 --> 00:00:20,300 all of that object as fields. 6 00:00:20,300 --> 00:00:21,840 That is a bit messy. 7 00:00:21,860 --> 00:00:27,210 What we want to do is call a constructor that updates the fields as soon as we create the object. 8 00:00:27,230 --> 00:00:33,080 So task one is to create a person constructor that receives four parameters. 9 00:00:33,080 --> 00:00:35,140 For now, we ignore the passport. 10 00:00:35,150 --> 00:00:42,430 So here we're going to create a new constructor that gets called whenever we create a person object. 11 00:00:42,440 --> 00:00:47,570 That constructor is going to receive four parameters during object creation. 12 00:00:47,570 --> 00:00:50,900 So the name it's going to receive a nationality. 13 00:00:50,930 --> 00:00:53,600 It will receive a date of birth. 14 00:00:54,630 --> 00:00:56,340 As well as a seat number. 15 00:00:57,050 --> 00:00:59,330 For now, we ignore the passport. 16 00:01:00,470 --> 00:01:08,330 D This keyword means the current object and what we can do is access the field of the current object 17 00:01:08,870 --> 00:01:11,730 and set it equal to the parameter that gets passed in. 18 00:01:11,750 --> 00:01:13,480 So we'll do that for the name. 19 00:01:13,490 --> 00:01:18,810 We will set the nationality field of that object equal to the nationality parameter. 20 00:01:18,830 --> 00:01:26,210 We will set the date of birth field equal to the date of birth parameter, and we can set the seat number 21 00:01:26,210 --> 00:01:29,180 field equal to the seat number parameter. 22 00:01:32,260 --> 00:01:32,680 All right. 23 00:01:32,680 --> 00:01:37,900 And now, as soon as we create an object of the person class, in order to invoke this constructor, 24 00:01:37,900 --> 00:01:41,020 we need to pass in the correct number of arguments. 25 00:01:41,020 --> 00:01:47,630 So we need to pass in a name, nationality, date of birth, and seat number. 26 00:01:47,650 --> 00:01:50,950 We will use the same values we're using over here. 27 00:01:57,160 --> 00:02:02,170 For now, we're ignoring the passport and we're just going to assign this person a seat. 28 00:02:02,170 --> 00:02:03,670 Number of five. 29 00:02:04,180 --> 00:02:04,990 All right. 30 00:02:04,990 --> 00:02:06,490 I think I did task one. 31 00:02:06,490 --> 00:02:13,420 And task to task three is to print every field as part of one string so we can just copy this over. 32 00:02:14,260 --> 00:02:15,820 How convenient. 33 00:02:16,720 --> 00:02:20,350 Here, I will print that person's name. 34 00:02:21,510 --> 00:02:24,630 Here, I will print that person's nationality. 35 00:02:26,330 --> 00:02:26,660 Here. 36 00:02:26,660 --> 00:02:29,510 I will print their date of birth. 37 00:02:30,630 --> 00:02:33,480 And here we can print their seat number. 38 00:02:35,940 --> 00:02:36,480 Okay. 39 00:02:36,490 --> 00:02:37,960 I think we're all done. 40 00:02:37,980 --> 00:02:40,080 We should be ready to visualize the run time. 41 00:02:40,080 --> 00:02:41,670 Let's do just that. 42 00:02:42,240 --> 00:02:45,840 I'm just going to put one breakpoint over here. 43 00:02:47,240 --> 00:02:47,990 And that's it. 44 00:02:53,120 --> 00:02:57,490 So here what we're doing is we're creating a new object of the person class. 45 00:02:57,500 --> 00:03:01,370 And as soon as we create the object, the constructor is going to get called. 46 00:03:01,730 --> 00:03:07,550 And what the constructor is going to do is set every single field inside of the current object that's 47 00:03:07,550 --> 00:03:11,240 being created equal to a parameter that gets passed in. 48 00:03:14,140 --> 00:03:19,240 So here we set the name field of the current object equal to Ray and Slim. 49 00:03:20,360 --> 00:03:25,760 Here we set the nationality field of the current object equal to Canadian. 50 00:03:28,200 --> 00:03:28,620 Here. 51 00:03:28,620 --> 00:03:34,260 We set the date of birth field of the current object equal to the date of birth that gets passed in 52 00:03:34,260 --> 00:03:36,000 11111. 53 00:03:36,120 --> 00:03:42,780 Here we set the seat number field of the current object equal to the seat number that gets passed in. 54 00:03:43,780 --> 00:03:44,800 All right. 55 00:03:45,190 --> 00:03:48,040 Now that we've initialized the current object. 56 00:03:50,500 --> 00:03:54,010 The person variable stores a reference to that object. 57 00:03:55,850 --> 00:03:59,990 And here we're printing all of the fields that belong to this object.