-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContactService.java
More file actions
47 lines (37 loc) · 1.53 KB
/
Copy pathContactService.java
File metadata and controls
47 lines (37 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package m3;
import java.util.TreeMap;
public class ContactService {
TreeMap<String, Contact> contacts = new TreeMap<String, Contact>(); // TreeMap allows for access by key
public void newContact(Contact contact) {
// method to add new contact, per requirement
if ((this.contacts.get(contact.getContactId()) == null)) { // requirement: IDs must be unique
this.contacts.put(contact.getContactId(), contact);
} else {
throw new IllegalArgumentException("Contact with given ID exists.");
}
}
public void removeContact(String contactId) {
// method to remove contact by ID, per requirement
this.contacts.remove(contactId);
}
public void updateContactFirstName(String contactId, String firstName) {
// method to update contact first name, per requirement
Contact contact = contacts.get(contactId);
contact.setFirstName(firstName);
}
public void updateContactLastName(String contactId, String lastName) {
// method to update contact last name, per requirement
Contact contact = contacts.get(contactId);
contact.setLastName(lastName);
}
public void updateContactPhoneNumber(String contactId, String phoneNumber) {
// method to update contact phone number, per requirement
Contact contact = contacts.get(contactId);
contact.setPhoneNumber(phoneNumber);
}
public void updateContactAddress(String contactId, String address) {
// method to update contact address, per requirement
Contact contact = contacts.get(contactId);
contact.setAddress(address);
}
}