Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I would like some help in completing this exercise. Thank You import java.util.A

ID: 3705639 • Letter: I

Question

I would like some help in completing this exercise. Thank You

import java.util.ArrayList;
import java.util.Arrays;

public class ContactManager {
// declare the contact ArrayList as an instance variable here.

  
  
  
  
/**
* Initialize an empty ContactManager.
*/
public ContactManager() {
throw new UnsupportedOperationException("Remove this line and replace with your implementation.");
}

/**
* Initialize a ContactManager which contains all the Contacts in the given
* array.
*/
public ContactManager(Contact[] contacts) {
throw new UnsupportedOperationException("Remove this line and replace with your implementation.");
}

/**
* Given 4 String parameters, add a contact to the contacts list. If first name
* or last name is null or an empty string, then do not add a contact but return
* false.
*
* Otherwise, create a new contact, and add the phone number to the new contact.
* If the phone number is in a valid format, add the contact to the list and
* return true. You may not rewrite the validity check method but can simply
* reuse the Contact class code written for L5.
*
* We allow adding duplicate contacts. Note that there is no limit to how many
* times this method can be called.
*
* @param fName
* @param lName
* @param mName
* @param phoneNumber
* @return a boolean value. See the description above
*/
public boolean addContact(String fName, String lName, String mName, String phoneNumber) {
throw new UnsupportedOperationException("Remove this line and replace with your implementation.");
}

/**
* Remove the Contact with Name n from your List. Make no changes if it doesn't
* exist.
*
* @param n
*/
public void removeContact(Name n) {
throw new UnsupportedOperationException("Remove this line and replace with your implementation.");
}

/**
* Return whether the Contact List contains a Contact with Name n or not. Hint:
* A 1-line solution exists.
*/
public boolean contains(Name n) {
throw new UnsupportedOperationException("Remove this line and replace with your implementation.");
}

/**
* Return the number of contacts (int) Hint: A 1-line solution exists.
*/
public int countContacts() {
throw new UnsupportedOperationException("Remove this line and replace with your implementation.");
}

/**
* Return a toString of the contacts. The toString() method should call the
* Contact toString() method and add a new line after every Contact, EXCEPT the
* last. Example Output with 2 contacts:
*
* Name: __________ (Phone Number: ___-___-____) Name: __________ (Phone Number:
* ___-___-____)
*/
public String toString() {
throw new UnsupportedOperationException("Remove this line and replace with your implementation.");
}

}

Explanation / Answer

import java.util.ArrayList; import java.util.Arrays; public class ContactManager { // declare the contact ArrayList as an instance variable here. private ArrayList list; /** * Initialize an empty ContactManager. */ public ContactManager() { list = new ArrayList(); } /** * Initialize a ContactManager which contains all the Contacts in the given * array. */ public ContactManager(Contact[] contacts) { for(Contact contact: contacts) { list.add(contact); } } /** * Given 4 String parameters, add a contact to the contacts list. If first name * or last name is null or an empty string, then do not add a contact but return * false. * * Otherwise, create a new contact, and add the phone number to the new contact. * If the phone number is in a valid format, add the contact to the list and * return true. You may not rewrite the validity check method but can simply * reuse the Contact class code written for L5. * * We allow adding duplicate contacts. Note that there is no limit to how many * times this method can be called. * * @param fName * @param lName * @param mName * @param phoneNumber * @return a boolean value. See the description above */ public boolean addContact(String fName, String lName, String mName, String phoneNumber) { if(fName == null || lName == null) { return false; } else { Contact contact = new Contact(new Name(fName, lName, mName)); if(contact.addPhoneNumber(phoneNumber)) { list.add(contact); return true; } else { return false; } } } /** * Remove the Contact with Name n from your List. Make no changes if it doesn't * exist. * * @param n */ public void removeContact(Name n) { for(int i = 0; i