Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For this milestone, you will focus on delivering the contact services. The purpose of these services is to add, update, and delete contact objects within
For this milestone, you will focus on delivering the contact services. The purpose of these services is to add, update, and delete contact objects within the application.
The contact service uses inmemory data structures to support storing contacts no database required In addition, there is no user interface for this milestone. You will verify the contact service through JUnit tests. The contact service contains a contact object along with the contact service. The requirements are outlined below.
Contact Class Requirements
The contact object shall have a required unique contact ID string that cannot be longer than characters. The contact ID shall not be null and shall not be updatable.
The contact object shall have a required firstName String field that cannot be longer than characters. The firstName field shall not be null.
The contact object shall have a required lastName String field that cannot be longer than characters. The lastName field shall not be null.
The contact object shall have a required phone String field that must be exactly digits. The phone field shall not be null.
The contact object shall have a required address field that must be no longer than characters. The address field shall not be null.
Contact Service Requirements
The contact service shall be able to add contacts with a unique ID
The contact service shall be able to delete contacts per contact ID
The contact service shall be able to update contact fields per contact ID The following fields are updatable:
firstName
lastName
Number
Address
To complete this project, you must submit a Contact Service zipped folder containing the following deliverables:
Contact.java
ContactService.java
ContactTest.java
ContactServiceTest.java
import java.util.HashMap;
public class ContactService
private final HashMap contacts new HashMap;
public void addContactContact contact
if contactscontainsKeycontactgetFirstName
throw new IllegalArgumentExceptionContact with this ID already exists";
contacts.putcontactgetFirstName contact;
public void deleteContactString contactID
contacts.removecontactID;
public void updateContactString contactID, String newFirstName, String newLastName, String newPhone, String newAddress
Contact contact contacts.getcontactID;
if contact null
throw new IllegalArgumentExceptionContact not found";
contact.setFirstNamenewFirstName;
contact.setLastNamenewLastName;
contact.setPhonenewPhone;
contact.setAddressnewAddress;
public Contact getContactString contactID
return contacts.getcontactID;
public class Contact
private final String contactID; not updatable
private String firstName;
private String lastName;
private String phone;
private String address;
public ContactString contactID, String firstName, String lastName, String phone, String address
if contactID null firstName null lastName null phone null address null
throw new IllegalArgumentExceptionFields cannot be null";
if contactIDlength firstName.length lastName.length phone.length address.length
throw new IllegalArgumentExceptionInvalid field lengths";
this.contactID contactID;
this.firstName firstName;
this.lastName lastName;
this.phone phone;
this.address address;
Getters and Setters for updatable fields
Omitted getter for contactID since it's not updatable
public String getFirstName
return firstName;
public void setFirstNameString firstName
if firstName null firstName.length
throw new IllegalArgumentExceptionInvalid first name";
this.firstName firstName;
public String getLastName
return lastName;
public void setLastNameString lastName
if lastName null lastName.length
throw new IllegalArgumentExceptionInvalid last name";
this.lastName lastName;
public String getPhone
return phone;
public void setPhoneString phone
if phone null phone.length
throw new IllegalArgumentExceptionInvalid phone";
this.phone phone;
public String getAddress
return address;
public void setAddressString address
if address null address.length
throw new IllegalArgumentExceptionInvalid address";
this.address address;
Please help with test classes.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started