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,900 --> 00:00:16,720 The purpose of this workbook is to define a function inside of the person class that every object is 4 00:00:16,720 --> 00:00:17,830 able to use. 5 00:00:17,860 --> 00:00:20,720 The function will be called Apply PLI passport. 6 00:00:20,740 --> 00:00:24,210 It will return a boolean and does not expect any parameters. 7 00:00:24,220 --> 00:00:27,420 So here we can say public boolean. 8 00:00:27,430 --> 00:00:28,990 It will return a boolean. 9 00:00:29,820 --> 00:00:33,960 Apply a passport and it does not expect any parameters. 10 00:00:35,470 --> 00:00:38,650 This code randomly returns zero or one. 11 00:00:38,650 --> 00:00:39,520 Simple enough. 12 00:00:39,520 --> 00:00:43,840 We covered math random very extensively in the functions section. 13 00:00:44,630 --> 00:00:50,660 And what we need to do is use this code to return true if the number equals one and false. 14 00:00:50,690 --> 00:00:59,060 Otherwise, it tells us not to use if else, to accomplish this task because we can just say return 15 00:00:59,150 --> 00:01:01,970 the number equals one. 16 00:01:03,020 --> 00:01:05,800 So if this is true, true will be returned. 17 00:01:05,810 --> 00:01:08,140 If this is false, false will be returned. 18 00:01:08,150 --> 00:01:13,430 There is no need to say if this is true, then return true. 19 00:01:13,460 --> 00:01:15,720 That would just be very redundant. 20 00:01:15,740 --> 00:01:17,840 Otherwise return false. 21 00:01:20,130 --> 00:01:22,330 This looks really tedious. 22 00:01:22,350 --> 00:01:26,850 We're already returning the result of a comparison, so we are good. 23 00:01:27,840 --> 00:01:32,130 Task two is inside the person class to find a function called to seat. 24 00:01:32,250 --> 00:01:39,780 It's void does not expect any parameters and it must use the following code to update the person's seat 25 00:01:39,780 --> 00:01:41,820 with a random seat number. 26 00:01:41,910 --> 00:01:46,890 So here we can say public void to seat. 27 00:01:47,070 --> 00:01:52,050 This function will allow any object that calls it to choose a random seat. 28 00:01:52,470 --> 00:01:55,850 Choosing a random seat will be based on the following code. 29 00:01:55,860 --> 00:01:57,690 So here we can say this. 30 00:01:58,510 --> 00:01:59,590 Not seat number. 31 00:01:59,620 --> 00:02:03,970 Actually, there is no need to use the this keyword because there is no conflicting parameter. 32 00:02:03,970 --> 00:02:09,580 By saying seat number, it's automatically going to reference the field of whatever object is calling 33 00:02:09,580 --> 00:02:10,449 this method. 34 00:02:10,449 --> 00:02:15,910 And we can set that equal to a random seat number between one and 11. 35 00:02:16,480 --> 00:02:19,310 So a range goes from 1 to 11. 36 00:02:19,330 --> 00:02:23,680 If you're wondering why that is, I highly recommend revisiting the function section. 37 00:02:24,910 --> 00:02:28,260 Now your starter project should contain one object. 38 00:02:28,270 --> 00:02:29,710 Let us confirm this. 39 00:02:29,980 --> 00:02:37,540 Indeed, it does call apply passport from your object and if the function returns true, we print the 40 00:02:37,540 --> 00:02:38,080 following. 41 00:02:38,110 --> 00:02:39,790 Otherwise we print this. 42 00:02:40,120 --> 00:02:41,620 So here we'll say. 43 00:02:42,780 --> 00:02:50,400 If a person does not apply passport, if the result of them applying for a passport returns true, then 44 00:02:50,400 --> 00:02:53,370 we're going to print the following message. 45 00:02:53,400 --> 00:02:54,630 Congratulations. 46 00:02:54,630 --> 00:02:57,720 Whatever the person's name is, your passport was approved. 47 00:02:57,750 --> 00:03:04,170 Otherwise, if applying for a passport ends up returning false, then we print this message. 48 00:03:04,170 --> 00:03:08,310 Sorry, we cannot process your application. 49 00:03:09,380 --> 00:03:14,780 And it seems like, according to the output, we print their fields first, then we give them the result 50 00:03:14,780 --> 00:03:16,180 of their application. 51 00:03:16,190 --> 00:03:20,330 So what we're going to do is put this after. 52 00:03:22,810 --> 00:03:25,240 And I think we're good. 53 00:03:25,270 --> 00:03:27,850 Let us visualize the runtime. 54 00:03:28,020 --> 00:03:29,020 As always. 55 00:03:30,280 --> 00:03:31,930 One breakpoint here. 56 00:03:32,790 --> 00:03:35,700 Only need one here, and then we can just keep stepping over. 57 00:03:37,010 --> 00:03:37,690 Okay. 58 00:03:39,950 --> 00:03:45,590 So here we're creating a new object of the person class, and we're calling the constructor that expects 59 00:03:45,590 --> 00:03:47,570 to receive four values. 60 00:03:47,600 --> 00:03:53,810 The constructor is going to receive every single value that we pass in as a parameter, such that this 61 00:03:53,810 --> 00:03:56,750 points to the current object that we just created. 62 00:04:00,150 --> 00:04:00,450 Here. 63 00:04:00,450 --> 00:04:04,500 We set this name equal to the name parameter. 64 00:04:05,880 --> 00:04:09,990 Here we set this nationality equal to the nationality parameter. 65 00:04:10,620 --> 00:04:14,940 We set the objects as date of birth equal to the date of birth parameter. 66 00:04:15,510 --> 00:04:20,610 And we set the object to seat number equal to the seat number that we passed in. 67 00:04:21,620 --> 00:04:27,320 All right, now the constructor is finished updating the object as Field's person variable is going 68 00:04:27,320 --> 00:04:29,840 to store a reference to that object. 69 00:04:30,020 --> 00:04:35,210 And here we print that object as field values minus the passport because it's null. 70 00:04:36,120 --> 00:04:41,880 And here that same person, that same object is going to call a PLI passport. 71 00:04:45,650 --> 00:04:51,530 So this points to the current object that's calling a PLI passport, the same object with a reference 72 00:04:51,530 --> 00:04:52,640 of at 14. 73 00:04:52,820 --> 00:04:58,250 And this is just going to generate a random integer that is either zero or one. 74 00:04:59,600 --> 00:05:02,880 In this case, it generates a number of zero. 75 00:05:02,900 --> 00:05:04,460 Zero does not equal one. 76 00:05:04,460 --> 00:05:07,400 So there are passport application is false. 77 00:05:08,820 --> 00:05:11,190 Which means else is going to get triggered. 78 00:05:11,640 --> 00:05:12,570 We are sorry. 79 00:05:12,570 --> 00:05:14,790 We cannot process your application. 80 00:05:15,540 --> 00:05:21,840 Okay, let's now try this again and hope that the next time it ends up being true. 81 00:05:21,870 --> 00:05:28,350 So this is just going to create a new object of the person class printing every single field value. 82 00:05:28,380 --> 00:05:30,780 We are applying for a passport again. 83 00:05:30,810 --> 00:05:32,490 Hopefully it's true. 84 00:05:32,610 --> 00:05:33,660 It is true. 85 00:05:33,660 --> 00:05:35,050 One equals one. 86 00:05:35,070 --> 00:05:38,490 Their passport application is going to get processed. 87 00:05:39,630 --> 00:05:41,550 Congratulations person. 88 00:05:41,850 --> 00:05:42,840 Get name. 89 00:05:42,840 --> 00:05:44,680 Your passport was approved. 90 00:05:44,700 --> 00:05:45,870 All right. 91 00:05:47,050 --> 00:05:50,950 And that is all we were able to achieve both outputs. 92 00:05:50,980 --> 00:05:55,290 This would look a little bit cleaner if you just run the code using terminal commands. 93 00:05:55,300 --> 00:05:59,620 So a Java C main, Java, Java main. 94 00:06:00,070 --> 00:06:05,230 And now you can run the code to your heart's content and you're going to get alternating results.