The hard part is over now we're going to add what's left of the Big Three steps, as well as a copy
constructor in a two string.
And so we can use Intellisense to autocomplete, the gutters and setters, get a name, get phone number.
Get birthdates.
Get a age.
Set name.
That phone number said birthdates.
First, we're going to make that a private.
We need to hide this setar because the color shouldn't be allowed to use it.
The birthdate that they pass in should automatically determine the age, so inside set birth date.
So far it's fine, which it's just updating the birth dates, but it also needs to convert that date
into an age.
We've already done that.
So you might think they just copy and paste the code from the constructor right onto here.
But you know me, I'm not a big fan of copying and pasting code, we need that logic to be in one place.
So I'll create a function that returns an integer.
It's called to age and it receives a birth date as a parameter.
And inside the function, I'm going to cut and paste the logic from earlier.
In return, the.
The pass method throws a checked exception once again, don't catch the exception from inside the method.
Instead, the method is going to throw the exception to that.
Whoever is calling it handles the failure.
So back in the constructor.
The field is going to store the return value from the two major method.
And while the code looks so much better, I'm really glad we did this.
And now here inside set birthdates.
We're going to call Sage.
And will convert the birthdate to age and pass it in as an argument to basically when the caller updates
the birth date, it's going to automatically update the field as well.
But now to age throws a pass exception, but we're not going to try catch inside of our method.
Instead, the method is going to throw the exception to that.
Whoever is calling it, whoever is the one that's providing the birth dates, they need to be the ones
to handle the failure.
Before we go on, this is a good place to test our code.
I'm going to go back to Main.
Put this back to 07.
And update the birthdate.
Instead of 07 will say 08.
A lot of breakpoint right here.
I'll step over creating the object.
The contact variable star is a reference that points to the object here we update the object on step
inside, it updates the birth date.
I'm going to step over this line and here it updates the age.
But as you can see, a month, does it really make a difference?
So we'll change the year.
And there you go.
Updating the birthdate automatically updates the.
If we keep going, finally runs and prints, process completes, we're good so far.
The next step is that a copy constructor, because at some point we're going to need a way to copy contact
objects without falling into the reference trap so we can simply copy this constructor and instead of
parameters, will be obtaining values from a source object.
Then said every field in the current object equal to that field value from a source object, nothing
new here.
Let's visualize what's going on back in Maine, I'm going to create a new contact object that copies
every field from this one.
New contact.
Contact.
This points to the new contact object that we just created.
Soares points to the object that we passed in.
And one by one, we're copying every value from the source object into the current object.
The next task tells us that every class that models an object should have a two string method somehow
attached to string method to the class.
Public string.
To string and we'll copy over the format that I left you.
And will replace the placeholders where we need to.
And perfect, we're done creating the contact class, let's test it out inside mean I'm going to print
the object.
And everything works beautifully.