The objective of this exercise is to create a basic contact list management system using a LinkedList in Java. You will model the process of adding contacts, searching for contacts, and displaying the contact list.
Imagine you are building a program to manage a contact list. Users can add contacts to the list, search for contacts by name, and display the list of contacts. You will implement this functionality using a LinkedList.
- Create a class named Contact with the following attributes:
- String name: to store the name of the contact.
- String phoneNumber: to store the phone number of the contact.
- Create a class named ContactList that includes the following methods:
- addContact that adds a new contact with the given name and phone number to the LinkedList.
- searchContact that searches for a contact by name and returns the contact's information if found.
- displayContacts that displays the details of all contacts in the list.
- Create instances of the ContactList class in the main method.
- Add contacts to the list, search for contacts, and display the contact list.