Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Programming project done in Java In this programming assignment, you will provide an abstract data type PhoneBook that can be used to represent sequences of
Programming project done in Java
In this programming assignment, you will provide an abstract data type PhoneBook that can be used to represent sequences of phone book entries regardless of the implementation. Your PhoneBook will be a sequence of objects of class Person. You will also need to define class Person that is a tuple (String personID, String phoneNum). The ADT Phone Book must support the following operations: int size() - return the current size of the sequence. void insert(int i, Person person) - Insert a new component before the i-th component of the sequence (using 0 for the index of the first component). (Provide a reasonable action for the case when the sequence has fewer than i components, e.g., insert the new element at the end of the sequence) Person remove(int i) - Remove the i-th component of the sequence and retum the object removed (Provide a reasonable action for the case when the sequence has fewer than i components, e.g., do nothing and retum null since the element to be removed does not exist already). Person lookup(int i) - Return the i-th component of the sequence (raise an exception if the sequence has fewer than i components). Provide two implementations of this ADT: a class PhBArrayList and a class PhBLinkedList. The first one must use an array to store the sequence of persons and the second a singly linked list. Notes: Using built-in Java classes, such as ArrayList, LinkedList, or iterator, is not allowed. Do not forget the issue of managing the real estate" (i.e., the fixed size of the array) in the case of the PhBArrayList implementation. In other words, you will need to intemally re-allocate the array as it grows or shrinks too much. You will also need to augment your ADT with an PhBIterator ADT (interface) and implementation(s) that allow efficient traversal of PhoneBook sequences without violating the information hiding principle (as discussed in class). Write a demo application (name it "Demo) utilizing this ADT. Your Demo class should include the following methods: A static method "void remove Duplicates(...) that accepts as arguments instances of either PhBArrayList or PhBLinkedList class and removes people that appear in both lists from one of the lists, so that the lists contain no people in common Note: this method should not be specific to either class that implements PhoneBook: the same method should work for instances of either class. The main method where you would: o Create an instance of PhBArrayList sequence and an instance of PhBLinkedList sequence, insert several elements into both using the insert(int i, Person person) method. Make sure to include some elements with the same personlD into both lists. Since your demo application does not care at which position you insert elements into the lists, please specify the positions that minimize the execution time for each list type. Explain in the comments your choice of the positions at which you insert your elements. o Print both sequences in a readable fomat; o Invoke the remove Duplicates method to remove items with common names from both lists o Print both resulting sequences in a readable format. In this programming assignment, you will provide an abstract data type PhoneBook that can be used to represent sequences of phone book entries regardless of the implementation. Your PhoneBook will be a sequence of objects of class Person. You will also need to define class Person that is a tuple (String personID, String phoneNum). The ADT Phone Book must support the following operations: int size() - return the current size of the sequence. void insert(int i, Person person) - Insert a new component before the i-th component of the sequence (using 0 for the index of the first component). (Provide a reasonable action for the case when the sequence has fewer than i components, e.g., insert the new element at the end of the sequence) Person remove(int i) - Remove the i-th component of the sequence and retum the object removed (Provide a reasonable action for the case when the sequence has fewer than i components, e.g., do nothing and retum null since the element to be removed does not exist already). Person lookup(int i) - Return the i-th component of the sequence (raise an exception if the sequence has fewer than i components). Provide two implementations of this ADT: a class PhBArrayList and a class PhBLinkedList. The first one must use an array to store the sequence of persons and the second a singly linked list. Notes: Using built-in Java classes, such as ArrayList, LinkedList, or iterator, is not allowed. Do not forget the issue of managing the real estate" (i.e., the fixed size of the array) in the case of the PhBArrayList implementation. In other words, you will need to intemally re-allocate the array as it grows or shrinks too much. You will also need to augment your ADT with an PhBIterator ADT (interface) and implementation(s) that allow efficient traversal of PhoneBook sequences without violating the information hiding principle (as discussed in class). Write a demo application (name it "Demo) utilizing this ADT. Your Demo class should include the following methods: A static method "void remove Duplicates(...) that accepts as arguments instances of either PhBArrayList or PhBLinkedList class and removes people that appear in both lists from one of the lists, so that the lists contain no people in common Note: this method should not be specific to either class that implements PhoneBook: the same method should work for instances of either class. The main method where you would: o Create an instance of PhBArrayList sequence and an instance of PhBLinkedList sequence, insert several elements into both using the insert(int i, Person person) method. Make sure to include some elements with the same personlD into both lists. Since your demo application does not care at which position you insert elements into the lists, please specify the positions that minimize the execution time for each list type. Explain in the comments your choice of the positions at which you insert your elements. o Print both sequences in a readable fomat; o Invoke the remove Duplicates method to remove items with common names from both lists o Print both resulting sequences in a readable formatStep 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