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

There are three class Contact, Name, and ContactMangeer Plz implement each class

ID: 3703914 • Letter: T

Question

There are three class Contact, Name, and ContactMangeer Plz implement each class thanks

public class Contact {

/**

   * Add private instance variables here. See the class structure given in the

   * assignment description.

   */

/**

   * Implement your constructor here. Initialize the phoneNumber to null.

   */

public Contact(Name name) {

}

/**

   * Implement your addPhoneNumber method here.

   *

   * The phone number should be in the format of three digits followed by a dash,

   * followed by another three digits, followed by a dash, and finally followed by

   * four digits (i.e., 301-405-2755). Return false if the phone number format is

   * incorrect or null.

   *

   */

public boolean addPhoneNumber(String pNumber) {

}

/**

   * Implement your toString method. The output should be in the format:

   *

   * Name: __________ (Phone Number: ___-___-____)

   *

   * For example, if a contact has the first name John, last name Doe and middle

   * name Xavier, and the phone number 123-456-7890, this should return:

   *

   * Name: Doe, John Xavier (Phone Number: 123-456-7890)

   *

   * Do not insert new line character after the last digit of the phone number.

   */

public String toString() {

}

/**

   * Implement your equals method here.

   *

   */

public boolean equals(Object obj) {

}

public class ContactManager {

  

/**

   * The instance variables are given below. Do NOT modify the two lines

   *

   */

private int nContacts;

private Contact[] contacts;

  

/**

   * Implement the constructor of ContactManager class. In the constructor,

   * allocate an array of Contact. Use the nMaxContact as the length of the array

   * Initialize the nContacts to 0 in the constructor.

   *

   */

public ContactManager(int nMaxContact) {

}

/**

   * Given 4 String parameters, add a contact to the contacts array. Before adding

   * a contact to the array, do a parameter sanity check in this method. If the

   * array is full, or if first name or last name is null or an empty string, do

   * not add a contact but return false instead. Middle name can be left as null

   * or an empty String. Note that we allow adding duplicate contacts.

   *

   * If the name is acceptable, create a new contact and add the phone number to

   * the contact by calling the addPhoneNumber method of the Contact object. If

   * the method returns false, do not add the contact to the array and return

   * false (i.e., we discard the contact instantiated.) Otherwise, add the contact

   * to the array and return true.

   *

   * @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) {

}

/**

   * Given a Contact object, return the number of contacts with the identical name

   * (i.e., they have identical first, last, and middle name. If the input

   * parameter is null, return -1.

   *

   * For example, if the contacts array contains 10 contacts and there are 3

   * elements have the same name, return 3.

   *

   * @return an int value. See the description above.

   */

public int countEqualContacts(Contact c) {

}

/**

   * This method returns the number of contacts (int)

   */

public int countContacts() {

}

}

public class Name {

/**

   * Add private instance variables here. See the class structure given in the

   * assignment description.

   */

/**

   * Add your constructor here, referring to the class figure given in the

   * assignment description.

   */

public Name(String firstName, String lastName, String middleName) {

}

/**

   * Implement your toString method. The output should be in the format:

   * "Lastname, FirstName Middlename". For example, if the first name is John,

   * last name is Doe and middle name is Xavier, this method should return:

   *

   * "Doe, John Xavier"

   *

   * If the middle name were empty or null, this this method should return:

   *

   * "Doe, John"

   *

   */

public String toString() {

}

/**

   * Complete the equals method

   */

public boolean equals(Object obj) {

}

}

Explanation / Answer

public class Name { /** * Add private instance variables here. See the class structure given in the * assignment description. */ private String firstName; private String lastName; private String middleName; /** * Add your constructor here, referring to the class figure given in the * assignment description. */ public Name(String firstName, String lastName, String middleName) { this.firstName = firstName; this.lastName = lastName; this.middleName = middleName; } /** * Implement your toString method. The output should be in the format: * "Lastname, FirstName Middlename". For example, if the first name is John, * last name is Doe and middle name is Xavier, this method should return: * * "Doe, John Xavier" * * If the middle name were empty or null, this this method should return: * * "Doe, John" * */ public String toString() { String str = String.format("%s, %s", lastName, firstName); if(lastName != null && !lastName.isEmpty()) { str += " " + lastName; } return str; } /** * Complete the equals method */ public boolean equals(Object obj) { Name n = (Name) obj; return firstName.equals(n.firstName) && lastName.equals(n.lastName) && ((middleName == null && n.middleName == null) || (middleName != null && lastName != null && middleName.equals(n.middleName))); } } public class Contact { /** * Add private instance variables here. See the class structure given in the * assignment description. */ private Name name; private String phoneNumber; /** * Implement your constructor here. Initialize the phoneNumber to null. */ public Contact(Name name) { phoneNumber = null; this.name = name; } public Name getName() { return name; } /** * Implement your addPhoneNumber method here. *

* The phone number should be in the format of three digits followed by a dash, * followed by another three digits, followed by a dash, and finally followed by * four digits (i.e., 301-405-2755). Return false if the phone number format is * incorrect or null. */ public boolean addPhoneNumber(String pNumber) { if (pNumber.length() == 12) { if (java.lang.Character.isDigit(pNumber.charAt(0)) && java.lang.Character.isDigit(pNumber.charAt(1)) && java.lang.Character.isDigit(pNumber.charAt(2)) && java.lang.Character.isDigit(pNumber.charAt(4)) && java.lang.Character.isDigit(pNumber.charAt(5)) && java.lang.Character.isDigit(pNumber.charAt(6)) && java.lang.Character.isDigit(pNumber.charAt(8)) && java.lang.Character.isDigit(pNumber.charAt(9)) && java.lang.Character.isDigit(pNumber.charAt(10)) && java.lang.Character.isDigit(pNumber.charAt(11)) && pNumber.charAt(3) == '-' && pNumber.charAt(7) == '-') { phoneNumber = pNumber; return true; } else { return false; } } else { return false; } } /** * Implement your toString method. The output should be in the format: *

* Name: __________ (Phone Number: ___-___-____) *

* For example, if a contact has the first name John, last name Doe and middle * name Xavier, and the phone number 123-456-7890, this should return: *

* Name: Doe, John Xavier (Phone Number: 123-456-7890) *

* Do not insert new line character after the last digit of the phone number. */ public String toString() { return String.format("Name: %s (Phone Number: %s)", name.toString(), phoneNumber); } /** * Implement your equals method here. */ public boolean equals(Object obj) { return true; } } public class ContactManager { /** * The instance variables are given below. Do NOT modify the two lines * */ private int nContacts; private Contact[] contacts; /** * Implement the constructor of ContactManager class. In the constructor, * allocate an array of Contact. Use the nMaxContact as the length of the array * Initialize the nContacts to 0 in the constructor. * */ public ContactManager(int nMaxContact) { contacts = new Contact[nMaxContact]; this.nContacts = 0; } /** * Given 4 String parameters, add a contact to the contacts array. Before adding * a contact to the array, do a parameter sanity check in this method. If the * array is full, or if first name or last name is null or an empty string, do * not add a contact but return false instead. Middle name can be left as null * or an empty String. Note that we allow adding duplicate contacts. * * If the name is acceptable, create a new contact and add the phone number to * the contact by calling the addPhoneNumber method of the Contact object. If * the method returns false, do not add the contact to the array and return * false (i.e., we discard the contact instantiated.) Otherwise, add the contact * to the array and return true. * * @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(nContacts == contacts.length || fName == null || lName == null) { return false; } else { Contact contact = new Contact(new Name(fName, lName, mName)); if(contact.addPhoneNumber(phoneNumber)) { contacts[nContacts++] = contact; return true; } else { return false; } } } /** * Given a Contact object, return the number of contacts with the identical name * (i.e., they have identical first, last, and middle name. If the input * parameter is null, return -1. * * For example, if the contacts array contains 10 contacts and there are 3 * elements have the same name, return 3. * * @return an int value. See the description above. */ public int countEqualContacts(Contact c) { if(c == null) { return -1; } else { int count = 0; for(int i = 0; i

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote