-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContact.java
80 lines (66 loc) · 2.13 KB
/
Contact.java
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
public class Contact {
// Global variables
private String contactID;
private String firstName;
private String lastName;
private String phoneNumber;
private String contactAddress;
// Contact constructor with required fields
public Contact(String id, String first, String last, String number, String address) {
setContactID(id);
setFirstName(first);
setLastName(last);
setPhoneNumber(number);
setContactAddress(address);
}
// Contact Field Getters
public String getContactID() {
return contactID;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public String getPhoneNumber() {
return phoneNumber;
}
public String getContactAddress() {
return contactAddress;
}
// Contact Field Setters
private void setContactID(String id) {
checkNameField(id);
contactID = id;
}
public void setFirstName(String first) {
checkNameField(first);
firstName = first;
}
public void setLastName(String last) {
checkNameField(last);
lastName = last;
}
public void setPhoneNumber(String number) {
if (number == null || number.length() != 10) {
throw new IllegalArgumentException("Invalid phone number: " + number);
}
phoneNumber = number;
}
public void setContactAddress(String address) {
if (address == null || address.length() > 30) {
throw new IllegalArgumentException("Invalid Address: " + address);
}
contactAddress = address;
}
// Function to check for valid field argument requirements
public void checkNameField(String fieldName) {
if(fieldName == null) {
throw new IllegalArgumentException("Invalid: " + fieldName + " is null");
}
if(fieldName.length() > 10) {
throw new IllegalArgumentException("Invalid: " + fieldName + " greater than 10 characters");
}
}
}