Please write this in Java, thank you
We want you to implement a java class that implements a contact list, asks for inputs from the user and throw exceptions where needed. The following requirements specify what fields you are expected to implement in your Contact class: • A private String firstName that represents the first name of the contact. – A private String lastName that represents the last name of the contact. – A private long tel_number that represents the phone number of the contact. The Contact class will have the following methods: A constructor that takes the three fields defined (firstName, lastName and tel_number) as arguments and assigns them A toString() method that displays first name, last name and phone number of the contact in the following format “555-987-1234”. A boolean method that takes a last name as an input and returns whether the current object has the same last name. A method getContact() that outputs a Contact object and throws a java.io.IOException as will be described below: It needs to request an input from the user for the first name, last name and phone number (use java.util.Scanner for that) In case the first name or last name is “USF throw an exception. In case the phone number does not have 10 digits throw an exception. It retumsa Contact object with the information typed by the user. The following requirements specify what fields you are expected to implement in your Contact List class: – A private Array of Contact objects named contacts. – A private int named size. The Contact List class will have the following methods: • Ano-arg constructor that assigns the contacts array a size of 5 and the variable size to 0. A public boolean method called full that specifies whether the array is full or not. • A public boolean method called add(Contact obj) that adds obj to the contacts array. It also increments the size by I. A public void method printAll that prints the contacts array with the current list of contacts. A public void method search(String LastName) that takes in a last name and prints the contacts whose last name corresponds to the variable LastName. A public int searchNumMatches(String LastName) that returns the count of contacts whose last names correspond to the variable LastName. The following requirements specify what fields you are expected to implement in your MainDriver class: • A menu() method that prints the following menu to the user: Type one of the following options: 1. Add a contact to the list. 2. Print out all list contacts. 3. Search for a contact last name. 4. Quit A main() method that requests an option from the user and oops until the user quits: Declare Scanner and Contact List objects. Display the menu to the user and implement the following options: Option 1: Use the full() method to determine if the Contact List object is full. In case there is space available, use the getContact() method to request the user input and add(Contact obj) method to add the new contact to the ContactList. Use try and catch to determine whether there was an exception based on the user input and display a message “The contact has been added” or “Error adding the contact, please verify”. Option 2: Use the printAll() method to print the elements of the contact list. Option 3: Ask the user to type a last name that will be searched in the array. Use the search NumMatches(String LastName) to confirm that there is a match. In case there is a match, use the search(String LastName) method to print the results. Option 4: Break the loop to end the program. Use your own test cases to verify the functionality of your code. Show transcribed image text We want you to implement a java class that implements a contact list, asks for inputs from the user and throw exceptions where needed. The following requirements specify what fields you are expected to implement in your Contact class: • A private String firstName that represents the first name of the contact.
– A private String lastName that represents the last name of the contact. – A private long tel_number that represents the phone number of the contact. The Contact class will have the following methods: A constructor that takes the three fields defined (firstName, lastName and tel_number) as arguments and assigns them A toString() method that displays first name, last name and phone number of the contact in the following format “555-987-1234”. A boolean method that takes a last name as an input and returns whether the current object has the same last name. A method getContact() that outputs a Contact object and throws a java.io.IOException as will be described below: It needs to request an input from the user for the first name, last name and phone number (use java.util.Scanner for that) In case the first name or last name is “USF throw an exception. In case the phone number does not have 10 digits throw an exception. It retumsa Contact object with the information typed by the user. The following requirements specify what fields you are expected to implement in your Contact List class: – A private Array of Contact objects named contacts. – A private int named size. The Contact List class will have the following methods: • Ano-arg constructor that assigns the contacts array a size of 5 and the variable size to 0. A public boolean method called full that specifies whether the array is full or not. • A public boolean method called add(Contact obj) that adds obj to the contacts array. It also increments the size by I. A public void method printAll that prints the contacts array with the current list of contacts. A public void method search(String LastName) that takes in a last name and prints the contacts whose last name corresponds to the variable LastName. A public int searchNumMatches(String LastName) that returns the count of contacts whose last names correspond to the variable LastName. The following requirements specify what fields you are expected to implement in your MainDriver class: • A menu() method that prints the following menu to the user: Type one of the following options: 1. Add a contact to the list. 2. Print out all list contacts. 3. Search for a contact last name. 4. Quit A main() method that requests an option from the user and oops until the user quits: Declare Scanner and Contact List objects. Display the menu to the user and implement the following options: Option 1: Use the full() method to determine if the Contact List object is full. In case there is space available, use the getContact() method to request the user input and add(Contact obj) method to add the new contact to the ContactList. Use try and catch to determine whether there was an exception based on the user input and display a message “The contact has been added” or “Error adding the contact, please verify”.
Option 2: Use the printAll() method to print the elements of the contact list. Option 3: Ask the user to type a last name that will be searched in the array. Use the search NumMatches(String LastName) to confirm that there is a match. In case there is a match, use the search(String LastName) method to print the results. Option 4: Break the loop to end the program. Use your own test cases to verify the functionality of your code.
Expert Answer
Answer to We want you to implement a java class that implements a contact list, asks for inputs from the user and throw exceptions…