Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

This assignment will test your skills in object-oriented programming with multiple classes and the use of Linked List as the data structure. In this assignment,

This assignment will test your skills in object-oriented programming with multiple classes and the use of Linked List as the data structure.

In this assignment, you will design a class called AddressBook that uses a Linked List to store nodes that are made up of Contacts. You must adapt the Node class that we wrote in class, and adapt and add to the Linked List class that we developed together (You cannot use java.util.LinkedList for this assignment).

Start by designing the Contact class that holds a persons last name, first name, street name, and phone number:

public class Contact{

private String lastName;

private String firstName;

private String streetName;

private String phone;

//complete the rest of the class by adding appropriate constructors, get, set methods, toString, etc.

}

Re-design the Node class to hold Contact as its data.

Re-design the Linked List class that we developed in class so that the methods will work with Nodes with Contacts as its data.

Finally, you will create the AddressBook class. It has a LinkedList and methods to add a contact, display all contacts, search for a specific contact and display it, or search and delete a specific contact.

AddressBook:

When a contact is added, it should be added in order alphabetically to the list by last name (and then by first name if there are multiple contacts with the same last name). To add alphabetically look at the compareTo String method which compares Strings lexicographically (returns an int >0, <0, or 0 which indicates order).

Displaying all the contacts should be formatted to show results lined up (e.g., in columns). See the example output.

Search should let users search on name, address or phone number. Search will find any contact where any associated instance variable contains the target search string, and prints all matches to the console. For example, if "elmore" is the search target and name is the search category, then any contact where elmore is the first name or last name should be displayed. Similarly, if "1234" is the search target and phone is the search category, all contacts with 1234 as part of their phone number should be displayed. As well, if the user searches the Street "Robie", it should return all the contacts that live on Robie Street.

The delete method should allow the user to either choose a contact to delete from the full address book or from a search on name, address or phone number (e.g., enters Robie to get a list of all contacts who live on Robie). The user will be presented with a numbered list of contacts (either with all contacts from the address book or from the search). Then the user will select the contact from the list to be deleted.

Note: you will need to deal with the situation where a user enters in a Contact with all the same information as an existing Contact. In this case, you could not allow duplicates to be added or when a user deletes a contact that has duplicate entries you could delete them all. Make sure you note in your comments how you are dealing with this.

Your AddressBook class will look like the UML diagram below:

AddressBook

- list : LinkedList ()

+ AddressBook ( ) : //initializes the LinkedList

+ addContact (Contact) : void //adds the given Contact in alphabetical order

+ removeContact (Contact) : void //removes the given Contact

+ getList () : LinkedList //returns the LinkedList of Contacts

+ search (String, int) : void //enter search word and category (e.g., 1 for name, 2 for address, 3 for phone)

+ displayAllContacts ( ) : void //prints the address book

Note: you can add supporting methods in the AddressBook if needed (make sure you properly comment these).

Demo the AddressBook class:

public class AddressBookDemo{

public static void main(String[] args){

//rest of the code

}

}

You should write a demo program that implements the AddressBook. Your complete program will have the following classes:

Contact.java

LinkedList.java

AddressBook.java

AddressBookDemo.java

A short example of output is below. The demo program should present a menu that allows the user to add a contact, display all contacts, search for a specific contact and display it, or search for a specific contact and delete it, and quit. Your output should be nicely formatted. Below is an example screen dialog.

Enter 1 to add contact, 2 to display, 3 to search, 4 to delete, 5 to quit: 1

Enter last name: Adams

Enter first name: John

Enter Street name: Vernon

Enter phone number: 555-1234

Enter 1 to add contact, 2 to display, 3 to search, 4 to delete, 5 to quit: 1

Enter last name: Smith

Enter first name: Amy

Enter Street name: Robie

Enter phone number: 555-4567

Enter 1 to add contact, 2 to display, 3 to search, 4 to delete, 5 to quit: 1

Enter last name: Brown

Enter first name: Adam

Enter Street name: Robie

Enter phone number: 555-9812

Enter 1 to add contact, 2 to display, 3 to search, 4 to delete, 5 to quit: 2

Name Street Number

Adams, John Vernon 555-1234

Brown, Adam Robie 555-9812

Smith, Amy Robie 555-4567

Enter 1 to add contact, 2 to display, 3 to search, 4 to delete, 5 to quit: 3

Enter 1 to search name, 2 to search address, 3 to search phone number: 3

Enter what to search: 555-9812

Name Street Number

Brown, Adam Robie 555-9812

Enter 1 to add contact, 2 to display, 3 to search, 4 to delete, 5 to quit: 3

Enter 1 to search name, 2 to search address, 3 to search phone number: 2

Enter what to search: Robie

Name Street Number

Brown, Adam Robie 555-9812

Smith, Amy Robie 555-4567

Enter 1 to add contact, 2 to display, 3 to search, 4 to delete, 5 to quit: 4

Enter 1 to search name, 2 to search address, 3 to search phone number, 4 to display all contacts: 2

Enter what to search: Robie

Name Street Number

1. Brown, Adam Robie 555-9812

2. Smith, Amy Robie 555-4567

Entry to delete: 2

Enter 1 to add contact, 2 to display, 3 to search, 4 to delete, 5 to quit: 2

Name Street Number

Adam, John Vernon 555-1234

Brown, Adam Robie 555-9812

Enter 1 to add contact, 2 to display, 3 to search, 4 to delete, 5 to quit: 5

Good-bye!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions