This video is going to cover the solution for part four, looking back at the requirements be classified,
another type of object, the contact manager and the contact manager as identified by the contacts that
it manages.
And it has two actions, adding and removing contacts.
We'll start by adding the contacts.
Field contact is plural, so it implies an array of Carra objects.
But we're going to use an array list because the number of elements can change.
As always of a class has failed, you need to apply the big three steps, we need to take instructor
at Getter and Setter.
The instructor is public shares the same name as the class, and it's going to receive no parameters
because in the beginning, the list of contacts is going to be empty.
We're just going to set the field equal to a new area list that can store contact objects.
Next, we want to get her gut contact that receives a one parameter.
The index of the contact object that they're trying to access.
In this letter is going to return a new copy of the contact object.
At the request, that index.
Next, we want to add a Seder that receives two parameters.
Contact object that you're going to use to update one of your Helmut's.
The index of the element that you want to update.
Then we're going to set the element at the requested index.
And set it equal to a new copy of the object being Pastan.
OK, that's all for the Big Three Steps.
Now we're going to get the method and contact, it's going to be void.
Receives one parameter, the contact they are trying to add.
And inside, we're going to insert a new copy of the contact object being Pastan.
The next action removes contact is also going to be void.
But it receives one parameter, the name of the contact that you want to remove.
So what we'll do is create a for loop that runs through the size of the array list.
Remember that array, less of a size, not a length and inside the loop.
We're going to get the contact object that every index I.
We'll get the name field of the contact and we'll check if it equals the name that was passed PASTAN
and if that's the case, then we're going to remove that contact from the aerialists.
Perfect.
We're done adding the big three steps, we added the two actions, the last thing we got to do is add
a two string method.
As always, public string to string.
I'm going to create a string named temp for a temporary it's going to be an empty string for now and
we'll return it's.
First will create a for loop that runs through the size of the aerialists.
And during each run, I'm going to get the two string of the contact object at the index I.
And then when I add that strength to the temp variable that we're returning.
And after adding the two string of a contact, we can add two lines so that we can separate it from
the next two string that gets passed into it.
And that's it now we're going to test our code.
Inside the workbook, I left you some values for objects that I want you to create.
First all, create an object of the contact manager class.
Manager is equal to a new object of the contact manager class.
And for the sake of expediency, I'm going to call that contact three times.
Once for Ryan.
Joe.
And Thomas.
Finally, we can print the contact to manager.
By printing the contract to manage our Java internally calls the two string method, which is going
to return a nicely formatted string of every contact and the contact lists.
Beautiful.
So the adduction works.
Now we're going to test the remove action, I'm going to remove the contact name Geo.
We run the up.
And everything works well.
This is the solution for part four.