Searching, Sorting, & Comparable Interface

You will use what you have learned from Chapter 8, 9, 13, and 14 in Big Java: Late Objects to complete the following program. Use what you have learned about Searching & Sorting, the Comparable Interface, Superclasses, Subclasses, Inheritance, Objects, Instance variables, Instance methods, Constructors, and Recursion to complete the project.
For examples constructing classes using a binary search, an array sort, and using the Comparable interface, please see:
Videos in iCollege for examples on these topics and how to comment your program correctly.
Code examples in iCollege (in the Java Code examples folder – these can be downloaded to your computer for reference)
**Class Notes in iCollege for Chapter 14 – **PLEASE read my Ch. 14 Comparable Interface notes for several examples!
**Please see the Comparable Interface Supplement.pdf for an example on using the Comparable interface.
Big Java Textbook – Section 14.6.2 (p. 669-670) and Section 14.8 (p. 678-681)
Please do not use any advanced material that is not in Chapter 8, 9, 13, or 14.
We will be completing our Programming Projects using Code Check. Nothing is required by you to use this program. For each project, I will provide a URL that will take you to the project to complete. Once you have completed the coding project(s) (you have unlimited attempts), you will download the Report from the Code Check website and upload this zipped file(s) to this Assignment folder. Inside this zipped file will be your completed code and your *calculated score based on testing. You may use your IDE (jGrasp/Eclipse) to write the code and then copy and paste over to Code Check, if desired.
*The calculated score will be located at the bottom of your submission in the form of (for example) “5/5 = 100%”, “4/5 = 80%”, “3/5 = 60%”, etc. IF YOU DO NOT obtain 100%, I encourage you to reach out for help on the Problem & Solutions Blog with your error messages so others can help. You can also view the “Common Code Check Errors” document located in iCollege. Please make sure you have viewed the “How to Use Code Check” video before starting.

We will be writing two classes, PhoneBookEntry.java and PhoneBookCatalog.java. In the PhoneBookEntry class, we will implement the Comparable interface of type PhoneBookEntry and override its compareTo method to sort our phone book entries.
UML Diagram
PART 1 – Writing the Phone Book Entry class:
PhoneBookEntry.java
This class represents a phone book entry (contact) that has a first name, a last name, and a phone number.
Instructions for Part 1:
Please go to the Code Check URL: Chapter 14 Project
Using your IDE (jGrasp, Eclipse, other), create a new project folder called PhoneBook
Inside this project folder, create a class file named PhoneBookEntry.java
**Note: Because we want to implement the Comparable interface, we will need to implement this in our class definition (see p. 679, Section 14.8.3). We will use the type PhoneBookEntry.
Write the Class comment describing the class and @author and @version tags
Declare and initialize 3 instance variables for the first name, last name, and phone number (see UML diagram).
Remember to declare them “private” instead of “public”. Also, please make sure to use the “this” keyword anytime you use your instance variables after declaring them.
Create a Constructor that takes the two names and phone number as parameters (see UML diagram)
**NEW: Inside the constructor, we need to handle unchecked exceptions. We must check that the parameters first name, last name, or phone number are not null. If they are, we must through an IllegalArgumentException with a message. (See 7.4 p. 352 Syntax 7.1).
Inside the constructor, initialize the instance variables with the parameters of the constructor
Write the 3 mutator (“setter”) methods to “set” the first name, last name, and phone number (see UML diagram). Remember to use “this” with instance variables.
**NEW: Inside each of the “setter” methods, we must handle unchecked exceptions for the parameters. Since we are dealing with Strings, we need to check if they are null and throw and IllegalArgumentException with a message. (See 7.4 p. 352 Syntax 7.1). You must do this for all 3 “setter” methods.
Write 3 accessor (“getter”) methods to “get” the first name, last name, and phone number (see UML diagram). Remember to use “this” with instance variables.
Write the toString() method (override), that takes no parameters and returns the formatted phone book entry as:
Name: Amy Jones
Phone number: 753-854-7895
Note: You can do this in one line using concatenation and n to join the names and phone number
Write the compareTo method (override) of the Comparable interface to determine how the entries should be sorted when calling Collections.sort (later in this project). The phone book entries should be sorted alphabetically by last name – if the last names are the same, then we will need to sort by the first name – if the first and last names are the same, we will need to sort by the phone number. I recommend using an if/else if/else statement to compare these instance variables to the “other” (See Ch. 9, section 9.6.3, p. 474). This uses separate if statements, but you should use the if/else if/else statement since we are comparing three different items.
Make sure you have commented your Class, Constructor, and all methods and inserted the correct @tags, as needed.
PART 2 – Implementing the PhoneBookCatalog class
PhoneBookCatalog.java
Instructions for Part 2:
This class will model a phone book catalog that contains individual PhoneBookEntry objects. You can think of this as an “old-fashioned” phone book or like the Contacts on your mobile device. Once we construct individual PhoneBook Entry objects in Part 1, we will add them to our phone book catalog.
In the same PhoneBook project folder from Part I, create a new class file named PhoneBookCatalog.java
Write the Class comment and @author and @version tags
Declare and initialize 1 instance variable of type ArrayList (see UML diagram)
Write a Constructor that no parameters and initializes the instance variable as a “new” ArrayList of type PhoneBookEntry (see UML diagram)
Write the addEntry method that takes a PhoneBookEntry object as a parameter and adds it to the ArrayList instance variable (see UML diagram).
**NEW: We need to handle the unchecked exception that the entry is not null. If it is, we must throw an IllegalArgumentException with a message. (See 7.4 p. 352 Syntax 7.1).
Write the getEntry method that takes an integer as a parameter and returns the entry located at that index in the ArrayList (see UML diagram).
**NEW: We need to handle the unchecked exception that the index is outside the range of out phone book catalog list. We can do this by checking if the index is < 0 or > the size of the list. If it is, we must throw an IllegalArgumentException with a message.
Write the removeEntry method that takes an integer as a parameter and removes the entry located at that index in the ArrayList (see UML diagram).
**NEW: We need to handle the unchecked exception that the index is outside the range of out phone book catalog list. We can do this by checking if the index is < 0 or > the size of the list. If it is, we must throw an IllegalArgumentException with a message.
Write the sort() method that uses the Collections sort method to sort the catalog. You do not need a return value.
Write the toString() method (override) that uses an enhanced for loop to traverse the ArrayList and create a String that is formatted as:

You will return this string from the method
**Make sure you have commented the class, constructor, and methods and included @param or @return tags as needed
Testing
Once you have written all classes, please download and save PhoneBookTester2.java in your project folder. Run PhoneBookTester2.java and correct any errors in your Object classes. **Make sure you understand the tester file. You should be able to understand the creation of objects and how we are testing their methods.

Last Completed Projects

topic title academic level Writer delivered