Question: This is a two part quesion the second part is based on the first part it may seem long but its mosly because I spaced

This is a two part quesion the second part is based on the first part it may seem long but its mosly because I spaced it out a lot to make it easier to read. Must be in Java

In this assignment, you will write a class that implements a contact book entry

Your Contact class should have the following private data:

The first name of the person

The last name of the person

The phone number of the person

The street address of the person

The city of the person

The state of the person

The Contact class should implement the Comparable interface.Your class should have the following public methods:

A constructor that initializes all the fields with information.

A constructor that initializes only the name and phone number.

accessor (getter) methods for all of the data members.

an update method that allows the user to change all information. (They must change all of it).

An overridden equals() method that can tell if one Contact is the same as another. It should have the method signature: public boolean equals(Object obj); We will define one Contact as being the same as another contact if the first and last names both match.

An overridden toString() method that creates a printable representation for a Contact object.

It should have the method signature: public String toString(); The String should be created in the following form: ,,phone number:,,, ,

A comparison method that looks like this: public int compareTo(Contact another); We will define this method in the following way: If the last name of another is lexicographically first, return a positive number. If the last name of another is lexicographically second, return a negative number. If the last names are the same and the first names are also the same, return 0. If the last names are the same and the first names are different, use the first names to determine the order. You must also declare the fact that Contact implements the Comparable interface. You must also write a main program that tests each of these methods

part 2.

you will implement a Contact List class. from the first part of the question Your ContactList should use an ArrayList (from the java collections hierarchy) as the underlying structure. Your ContactList class must implement the Iterable interface(!) and should have the following functionality:

Constructors:

- A constructor that creates an empty ContactList.

- A constructor that uses an array of Contacts in order to initialize the ContactList.

Operations:

- A method that searches for a particular contact by last name, and returns a reference to the Contact. If there is no such Contact, a sentinel value should be returned.

- A method that searches for a Contact by phone number, and returns a reference to the Contact. If there is no such Contact, a sentinel value should be returned.

- A function that searches for and returns a ContactList containing all Contacts with a last name starting with a particular letter. If there are no such Contacts, you should return the empty ContactList.

- A method that searches for and returns a ContactList containing all Contacts that live in a particular city. If there are no such Contacts, you should return the empty ContactList.

- A method that allows you to add a Contact to the ContactList. You should only add a Contact to the list if it is not there already.

A method that returns the size of the ContactList.

- A method that allows you to remove a Contact from the ContactList.

- A method that allows the client to get a Contact from the ContactList by index. An IndexOutOfBoundsException should be thrown if that index doesnt exist.

- An overridden equals() method. Lets define one ContactList being equal to another if they contain the same Contacts (but not necessarily in the same order.)

- An overridden toString() method that creates a representation for a ContactList. You should use StringBuilder and not String to synthesize your representation. (obviously, you have to return a String at the end). - An iterator() method that allows you to iterate through a ContactList. ( use the ArrayLists own iterator). .

You must also write a test program for the ContactList class.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!