In the first video, we implemented tasks one, two and three, and we loaded all the contacts into
the contact list except for Geo, because her birthdate isn't valid.
Now on to the final task for part six, which is to create a function named at manage contacts.
We're going to be interacting with the user and managing our contacts through this function.
So I'm going to start by creating a new object of the scanner class.
This scanner object is going to receive input from the system.
System in.
And the Java Dark tells us to create an infinite loop.
So we'll do just that.
And we need to ask the user to add or remove a contact or exit.
I'm just going to copy what we have from the workbook.
And after asking the user for their response, we're going to pick it up using scanned next line.
Kano if their response happens to equal a.
We're going to copy the following from the workbook, which further prompts the user for their name,
phone number and birthdate.
Then we're going to pick up every answer using scanned next line.
And now from the information they provided, we can add a new contacts manager and contacts.
And we'll create a new contact from the name.
Number and birth date that they passed in.
Here, we get an error.
That's because the contact constructor can throw a pass exception.
A pass exception is a checked exception.
So if you want to call this constructor, job is going to force you to try to run the code.
And if the code happens to fail, you need to catch the pirates exception.
And we'll just print the message that comes out of it.
All right.
And after writing the contact, the article tells us to use a finally blocked print.
Updated contact.
Followed by the updated list of contacts.
That's all for case.
If it's case B and they want to remove a contact.
Then we'll just ask them who they'd like to remove.
Then we can call a manager and remove contact and remove whatever name value the user.
Paston.
All right.
And if the user chooses C or anything else, really just break the loop.
And after the wire loop, don't forget to close scatter.
All right, now, back in the main method, we can call manage contacts.
I see that.
I've called that managed contact.
Let me just make sure it's plural.
Think we're now ready to test each case.
I'll start by testing, Casey.
I'll add another contact named Zack.
With a phone number of 111, two, two, two, three, three, three and with a birth date of 12, 12,
1995.
Next thing I'll do is remove a contact.
I'll remove Zack.
And woops, forget the print, the updated contact after removing them.
Let's try it again.
All that dark again with the same phone number as before.
Same birth date.
And get.
Just like that.
Zach has gone.
Finally, I'll just exit.
And that's all for adding interactivity to the application.
If you want to visualize what's going on, feel free to add breakpoints and launch the debugger.
Otherwise.
I hope you're ready for part seven.
I'll see you in there.