Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You will use your OrderedList collection class in an application that needs to maintain two subsets of items, one subset is of type and the

You will use your OrderedList collection class in an application that needs to maintain
two subsets of items, one subset is of type and the other subset is of type .
Note: test all methods in OrderedList before you start implementing the method in
TypesLists.
The requirements of the TypesLists class are as follows:
two instance variables:
o List: a private instance variable of type OrderedList that is
used to store items of type ItemA.
o List: a private instance variable of type OrderedList that is
used to store items of type ItemB.
Implement the following methods. Use the exact method headers as specified while replacing
Item with your specific item name.
1. a constructor to create a collection with two empty ordered lists. You have to call the
constructor of ItemOrderedList to initialize the lists to be ready to add items to them.
2. void add(Item element): checks the type of the input element using instanceof
and adding it to the appropriate list.
3. int sizeOf(): returns the number of nodes in List.
4. int sizeOf(): returns the number of nodes in List.
5. void display(): displays the contents of List list. Note that this
method displays the list on the screen and does NOT return a String representation of the list.
6. void display(): displays the contents of List list. Note that this
method displays the list on the screen and does NOT return a String representation of the list.
7. boolean add(int index, Item element): adds element to the appropriate list at
the given index where the head node is at index 1. If index is greater than the list size, then
the element is added as the last element in the linked list. The method does not do anything
if index is less than 1. The method returns true if the item is added and false otherwise.
8. boolean remove(Item target): removes one occurrence from target from the
appropriate list if any. The method returns true if an item is removed and false otherwise. All
other items in the list should remain in the same order. Use equals() method to search for
target.
9. boolean remove(int index): removes the item located at position index
in List where the head node is at index 1. The method returns true if an item is
removed and false if no element is removed because index is negative or beyond the list
length. This method should not change the order of the other elements in the list.
10. boolean remove(int index): removes the item located at position index
in List where the head node is at index 1. The method returns true if an item is
removed and false if no element is removed because index is negative or beyond the list
length. This method should not change the order of the other elements in the list.
11. int indexOf(Item target): returns the index of the first occurrence of target if
any and returns -1 if target is not in the list. Use equals() method to search for target.
12. ItemA get(int index): returns the item at position index in List
and returns null if index is less than 1 or greater than the size of the list.
13. ItemB get(int index): returns the item at position index in List
and returns null if index is less than 1 or greater than the size of the list.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Spatio Temporal Database Management International Workshop Stdbm 99 Edinburgh Scotland September 10 11 1999 Proceedings Lncs 1678

Authors: Michael H. Bohlen ,Christian S. Jensen ,Michel O. Scholl

1999th Edition

3540664017, 978-3540664017

More Books

Students also viewed these Databases questions

Question

What is the complement of 0.68?

Answered: 1 week ago

Question

Explain the process of MBO

Answered: 1 week ago