mirror of
https://github.com/didyouexpectthat/cs-320.git
synced 2024-11-20 20:00:08 -08:00
102 lines
2.9 KiB
Java
102 lines
2.9 KiB
Java
/*
|
|
Cody Cook
|
|
CS-320-H7022 Software Test Automation & QA 23EW2
|
|
2023/11/11
|
|
*/
|
|
|
|
public class Contact {
|
|
|
|
// declare private string
|
|
private String id;
|
|
private String firstName;
|
|
private String lastName;
|
|
private String phone;
|
|
private String address;
|
|
|
|
// declare final integers for lengths
|
|
private final int lengthId = 10;
|
|
private final int lengthName = 10;
|
|
private final int lengthPhone = 10;
|
|
private final int lengthAddress = 30;
|
|
|
|
// set constructor
|
|
public Contact(String id, String firstName, String lastName, String phone, String address) {
|
|
this.setId(id);
|
|
this.setFirstName(firstName);
|
|
this.setLastName(lastName);
|
|
this.setLastName(lastName);
|
|
this.setPhone(phone);
|
|
this.setAddress(address);
|
|
}
|
|
|
|
// Getter methods for the contact fields
|
|
public String getId() {
|
|
return id;
|
|
}
|
|
|
|
public String getFirstName() {
|
|
return firstName;
|
|
}
|
|
|
|
public String getLastName() {
|
|
return lastName;
|
|
}
|
|
|
|
public String getPhone() {
|
|
return phone;
|
|
}
|
|
|
|
public String getAddress() {
|
|
return address;
|
|
}
|
|
|
|
private void setId(String id) {
|
|
/* Contact should not look at ALL Contacts to determine if this is a unique ID
|
|
- That will fail when trying to add to the list in ContactService. */
|
|
// Appears with low coverage as a private function cannot be called in a test case
|
|
|
|
// Add validation logic to check character limitations
|
|
if (id == null || id.length() > this.lengthId || id.length() == 0) {
|
|
throw new IllegalArgumentException("ID must be " + lengthId + " characters or less.");
|
|
}
|
|
this.id = id;
|
|
}
|
|
|
|
// Setter methods for the contact fields that can be updated
|
|
public void setFirstName(String firstName) {
|
|
// Add validation logic to check character limitations
|
|
if (firstName != null && firstName.length() <= lengthName && firstName.length() > 0) {
|
|
this.firstName = firstName;
|
|
} else {
|
|
throw new IllegalArgumentException("First name must be " + lengthName + " characters or less.");
|
|
}
|
|
}
|
|
|
|
public void setLastName(String lastName) {
|
|
// Add validation logic to check character limitations
|
|
if (lastName != null && lastName.length() <= lengthName && lastName.length() > 0) {
|
|
this.lastName = lastName;
|
|
} else {
|
|
throw new IllegalArgumentException("Last name must be " + lengthName + " characters or less.");
|
|
}
|
|
}
|
|
|
|
public void setPhone(String phone) {
|
|
// Add validation logic to check character limitations
|
|
if (phone != null && phone.length() == lengthPhone) {
|
|
this.phone = phone;
|
|
} else {
|
|
throw new IllegalArgumentException("Phone must be " + lengthPhone + " characters.");
|
|
}
|
|
}
|
|
|
|
public void setAddress(String address) {
|
|
// Add validation logic to check character limitations
|
|
if (address != null && address.length() <= lengthAddress && address.length() > 0) {
|
|
this.address = address;
|
|
} else {
|
|
throw new IllegalArgumentException("Address must be " + lengthAddress + " characters or less.");
|
|
}
|
|
}
|
|
}
|