Consider a class PersonAddress that represents an entry in an address book. Its attributes are

• The first name of the person
• The last name of the person
• The e-mail address of the person
• The telephone number of the person
It will have methods to
• Access each attribute
• Change the e-mail address
• Change the telephone number
• Test whether two instances are equal based solely on name
a. Write a method heading for each method.
b. Write preconditions and postconditions for each method.
c. Write some Java statements that test the class.
d. Implement the class.


a)```
public String getFirstName()
public String getLastName()
public String getEmailAddress()
public String getPhoneNumber()
public void updateEmail(String newEmail)
public void updatePhone(String newPhone)
public boolean equal(PersonAddress otherPerson)
```

b)
public String getFirstName()
Precondition: none.
Postcondition: The first name was returned.

public String getLastName()
Precondition: none.
Postcondition: The last name was returned.

public String getEmailAddress()
Precondition: none.
Postcondition: The email address was returned.

public String getPhoneNumber()
Precondition: none.
Postcondition: The phone number was returned.


public void updateEmail(String newEmail)
Precondition: none.
Postcondition: The email address was changed to newEmail.


public void updatePhone(String newPhone)
Precondition: none.
Postcondition: The phone number was changed to newPhone.

public boolean equal(PersonAddress otherPerson)
Precondition: otherPerson is not null.
Postcondition: True was returned if the first and last names match.

c&d)
See the code in PersonAddress.java.

Computer Science & Information Technology

You might also like to view...

The value in ________ local variable is retained between function calls.

A) a global B) an internal C) a static D) a dynamic E) no

Computer Science & Information Technology

Neutral carriers are prohibited from making decisions on what communication to carry or whose communication to carry.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

When powering on a computer, you notice that the hard drive does not spin. What will you check?

A) Cabling B) BIOS C) Disk Management D) Device Manager

Computer Science & Information Technology

When planning an information system, a company must consider how a new system will interface with older systems, which are called _____.?

A. ?enterprise applications B. ?network operating systems (NOS) C. ?operating applications D. ?legacy systems

Computer Science & Information Technology