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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started