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,920 --> 00:00:12,930 Welcome to Workbook 7.21. 4 00:00:12,960 --> 00:00:20,490 Task one is to create a new file named person Java, which is going to contain our person class. 5 00:00:20,790 --> 00:00:22,800 All right, back to task one. 6 00:00:22,830 --> 00:00:28,200 The person class will define the following fields so we can just go ahead and copy and paste them. 7 00:00:30,070 --> 00:00:36,490 Our class, our blueprint will declare that every single person needs to have a name, nationality, 8 00:00:36,490 --> 00:00:39,520 date of birth, passport and seat number. 9 00:00:39,550 --> 00:00:45,340 So now, instead of task two, we can create one object of the person class. 10 00:00:45,340 --> 00:00:49,090 So back in our main class, we will create the main method. 11 00:00:50,600 --> 00:00:51,500 All right. 12 00:00:52,200 --> 00:00:55,710 The first object I will create will be of type person. 13 00:00:56,680 --> 00:00:58,660 I will call the variable person. 14 00:00:59,620 --> 00:01:06,310 And the person variable will store a reference to a brand new object of the person class. 15 00:01:07,320 --> 00:01:13,710 This object is going to automatically define five fields, which we can print out right now based on 16 00:01:13,710 --> 00:01:15,460 the instructions and task two. 17 00:01:15,480 --> 00:01:18,420 So we will print the person's name. 18 00:01:21,470 --> 00:01:23,330 We can print their nationality. 19 00:01:24,430 --> 00:01:27,640 Third date of birth, their passport. 20 00:01:27,940 --> 00:01:29,440 And what was the fifth one? 21 00:01:29,440 --> 00:01:30,760 Their seat number. 22 00:01:34,150 --> 00:01:35,800 I'll spin up a new terminal. 23 00:01:37,430 --> 00:01:38,540 Java Sea. 24 00:01:38,540 --> 00:01:39,950 Main Java. 25 00:01:40,910 --> 00:01:41,960 Java Main. 26 00:01:43,740 --> 00:01:44,280 All right. 27 00:01:44,280 --> 00:01:46,680 This is the result that we expect. 28 00:01:46,710 --> 00:01:53,460 It makes sense that our person starts off by having a name of nul, a nationality of null, a date of 29 00:01:53,460 --> 00:01:59,520 birth and passport of null and the seat number because it's an integer by default it starts off at zero. 30 00:01:59,550 --> 00:02:03,300 So task three is to update each field in the object before printing them. 31 00:02:03,300 --> 00:02:08,729 So here what I'm going to do is say person dot name is equal to. 32 00:02:09,120 --> 00:02:10,710 I'll just use my own name. 33 00:02:12,060 --> 00:02:12,570 Person. 34 00:02:12,870 --> 00:02:16,350 Nationality is equal to Canadian. 35 00:02:18,040 --> 00:02:21,090 Person date of birth is equal to. 36 00:02:21,100 --> 00:02:23,500 I'll just put a bunch of random numbers. 37 00:02:24,410 --> 00:02:26,420 Person dot passport. 38 00:02:26,870 --> 00:02:31,940 This array is going to contain the name and nationality and date of birth of that person. 39 00:02:31,940 --> 00:02:36,230 So you might think to use the shorthand initialization that we've been using before. 40 00:02:36,230 --> 00:02:37,760 So person name. 41 00:02:40,160 --> 00:02:40,560 Person. 42 00:02:40,850 --> 00:02:41,930 Nationality. 43 00:02:57,260 --> 00:02:58,610 New string. 44 00:02:59,750 --> 00:03:05,480 Then we can say person, seat number and set that equal to something like five. 45 00:03:06,170 --> 00:03:06,680 All right. 46 00:03:06,680 --> 00:03:08,570 Go ahead and rerun our code. 47 00:03:10,230 --> 00:03:11,950 And we are golden. 48 00:03:11,970 --> 00:03:21,090 There is one mistake that I made and that we should use arrays to string to print the following. 49 00:03:25,700 --> 00:03:27,620 Go ahead and rerun your code. 50 00:03:29,280 --> 00:03:30,120 Perfect. 51 00:03:34,760 --> 00:03:35,960 All right. 52 00:03:36,750 --> 00:03:38,130 Debug the runtime. 53 00:03:43,350 --> 00:03:46,980 So here we are creating a new object of the person class. 54 00:03:48,060 --> 00:03:52,170 The variable automatically stores a reference to that object. 55 00:03:52,440 --> 00:03:56,370 The object's fields by default start at null and zero. 56 00:03:56,640 --> 00:03:58,980 Here we update the objects name. 57 00:03:59,490 --> 00:04:01,470 Here we update their nationality. 58 00:04:01,500 --> 00:04:04,140 Here we update that person's date of birth. 59 00:04:04,170 --> 00:04:06,150 Here we update their passport. 60 00:04:06,150 --> 00:04:08,760 And here we update their seat number. 61 00:04:09,030 --> 00:04:13,680 And now we're just printing every single field that belongs to this object. 62 00:04:17,130 --> 00:04:17,730 That's all. 63 00:04:17,760 --> 00:04:20,820 I really hope you enjoyed watching the solution.