Question: Java program: Array of Objects Instructions Create two classes (two files). The Contact class should have String fields for the name and the phone number.

Java program: Array of Objects
Instructions

Create two classes (two files).

The Contact class should have String fields for the name and the phone number. It should have

getters and setters for each field,

a setter with parameters for both,

a constructor with parameters for both,

a toString to return both fields with a space between,

a compareTo(Contact other) method to return a call to compareToIgnoreCase comparing the name fields in this and other.

The driver class should contain a main method that creates an array of 1000 Contact objects. It should prompt the user for a name and a phone number, then add a new Contact to the array and increment the count of elements in the array until the user just hits enter in response to the prompt for the name.

Then, it should sort the array by name, using the compareTo method in the Contact class to compare Contacts, using bubble sort.

Then, it should repeatedly prompt for a name or just enter to quit and search for the Contact using binary search and print the Contact, or a message saying that the name was not found.

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!