Before we start, did you try solving the workbook yourself?
If not, please click the link in the resources folder and follow the instructions for this workbook.
Welcome to Workbook 7.21.
Task one is to create a new file named person Java, which is going to contain our person class.
All right, back to task one.
The person class will define the following fields so we can just go ahead and copy and paste them.
Our class, our blueprint will declare that every single person needs to have a name, nationality,
date of birth, passport and seat number.
So now, instead of task two, we can create one object of the person class.
So back in our main class, we will create the main method.
All right.
The first object I will create will be of type person.
I will call the variable person.
And the person variable will store a reference to a brand new object of the person class.
This object is going to automatically define five fields, which we can print out right now based on
the instructions and task two.
So we will print the person's name.
We can print their nationality.
Third date of birth, their passport.
And what was the fifth one?
Their seat number.
I'll spin up a new terminal.
Java Sea.
Main Java.
Java Main.
All right.
This is the result that we expect.
It makes sense that our person starts off by having a name of nul, a nationality of null, a date of
birth and passport of null and the seat number because it's an integer by default it starts off at zero.
So task three is to update each field in the object before printing them.
So here what I'm going to do is say person dot name is equal to.
I'll just use my own name.
Person.
Nationality is equal to Canadian.
Person date of birth is equal to.
I'll just put a bunch of random numbers.
Person dot passport.
This array is going to contain the name and nationality and date of birth of that person.
So you might think to use the shorthand initialization that we've been using before.
So person name.
Person.
Nationality.
New string.
Then we can say person, seat number and set that equal to something like five.
All right.
Go ahead and rerun our code.
And we are golden.
There is one mistake that I made and that we should use arrays to string to print the following.
Go ahead and rerun your code.
Perfect.
All right.
Debug the runtime.
So here we are creating a new object of the person class.
The variable automatically stores a reference to that object.
The object's fields by default start at null and zero.
Here we update the objects name.
Here we update their nationality.
Here we update that person's date of birth.
Here we update their passport.
And here we update their seat number.
And now we're just printing every single field that belongs to this object.
That's all.
I really hope you enjoyed watching the solution.