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

Can we slove it without using new Contact()? k* * Given 4 String parameters, add

ID: 3703939 • Letter: C

Question

Can we slove it without using new Contact()?

k* * 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) i if(nContacts contacts.length fName - null I lNamenull) £ return false; } else i Contact contact - new. ContactCnew. Name(fName...Name,..mName).. .phoneNumber if(contact.addPhoneNumber(phoneNumber)) i contacts[nContactst+]contact; return true; } else i return false;

Explanation / Answer

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; } } }

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