Samsmug, a cell phone company, has hired you to write software that manages a list of contacts. Samsmug users would like to be able to search their contact list based on various criteria. This assignment emphasizes searching and sorting along with processing Strings, arrays, and Lists.
A Contact
is defined as an entity having an id, first name and last name. In addition, a Contact
will have zero-or-more emails associated with them and zero-or-more phone numbers. The UML class diagram given below is a design that supports this understanding of a Contact
. You must write this class. Contacts
must support conversion to textual representation in the standard fashion. The textual representation of a Contact is given by example as “Hunt, Kenny, XCGBHAGGGG, {111-222-3333, 222-333-4444}, {hunt@gmx.org}” where the element values should be self explanatory.
Contact |
#List<String> emails, phoneNumbers // these are lists of the emails and phone numbers for the contact. |
#String firstName, lastName, id // id is a string of digits and letters of any case. |
+Contact(String fn, String ln, String id) // A contact having firstName fn, lastName ln, and the specified id. |
+String getFirstName() // returns the first name. |
+String getLastName() // returns the last name. |
+String getId() // returns the id |
+List<String> getEmails() // returns the emails. |
+List<String> getPhoneNumbers() // returns the phone numbers. |
+boolean addEmail(String email) // associates this email with the contact. If the email is already associated with this contact then the email is not associated with the contact. If the email doesn’t contain an ‘@’ character or contains more than one ‘@’ character, then it is not associated. If the email doesn’t end in a three letter suffix then it is not associated (i.e. it must end in a “.CCC” where C is any alphabetic character). Returns true if the contact is modified and false otherwise. |
+boolean addPhoneNumber(String phone)
// associates this phone number with the contact. If the phone number is not of the form ‘DDD-DDD-DDDD’ (where D represents a character between ‘0’ and ‘9’) then it is not added. If the phone number is already associated with this contact, then the phone number is not associated with the contact. Returns true if the contact is modified and false otherwise.
|
A ContactManager
is a class that manages many Contacts.
ContactManager |
#Contact[] contacts // the contacts that this object manages |
+ContactsManager(Contact[] contacts)
// A contact manager with the specified contacts. The array may be of any length but it will not
contain a "null" nor will it contain any duplicate element |
+Contact getById(String id)
// returns the contact having the specified id or null if no such contact exists. |
+List<Contact> getByFirstName(String fn)
// returns a list of all contacts having the specified first name (fn). |
+List<Contact> getByLastName(String ln)
// returns a list of all contacts having the specified last name (ln). |
+Contact getByPhone(String phone)
// returns the contact associated with the specified phone number or null if no such contact exists. |
+Contact getByEmail(String email)
// returns the contact associated with the specified email or null if no such contact exists. |
+List<Contact> getContacts()
// returns a list of all contacts that this manager manages. |
+boolean addEmailTo(Contact contact, String email) // associates this email with the contact. If the email is already associated with any contact then the email is not associated with the contact. If the email doesn’t contain an ‘@’ character or contains more than one ‘@’ character, then it is not associated. If the email doesn’t end in a three letter suffix then it is not associated (i.e. it must end in a “.CCC” where C is any alphabetic character). Returns true if the contact is modified and false otherwise. |
+boolean addPhoneNumberTo(Contact contact, String phone)
// associates this phone number with the contact. If the phone number is not of the form ‘DDD-DDD-DDDD’ (where D represents a character between ‘0’ and ‘9’) then it is not added. If the phone number is already associated with any contact, then the phone number is not associated with the contact. Returns true if the contact is modified and false otherwise.
|
+void print()
// prints all contacts to the terminal window. The contacts must be printed in alphabetically ascending order of last name. |
+public int getNumberOfContacts()
// returns the number of contacts that this manager is managing.
|
Add the following methods to the ContactManager
class.
ContactManager |
+List<String> allEmails(String sortOrder)
// This returns a list of all emails that are associated with any contact. The returned list must be sorted in either ascending order (if sortOrder is "ASC")
or descending order (if sortOrder is "DSC") or in ascending order of three-letter suffix (if sortOrder is "SASC") or in descending order of three-letter suffix (if
sortOrder is "SDSC"). If sortOrder is any other value, the ordering of the emails is not specified. |
+String[] allPhones(boolean isAscending)
// This returns a list of all phone numbers that are associated with any contact. The returned array must be sorted in either ascending (if isAscending is true)
or descending (if isAscending is false) order. |
Email two Java files as attachments. Make sure they are sent as attachments and not links.