Answered step by step
Verified Expert Solution
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.
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.
void addItem element: checks the type of the input element using instanceof
and adding it to the appropriate list.
int sizeOf: returns the number of nodes in List.
int sizeOf: returns the number of nodes in List.
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.
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.
boolean addint index, Item element: adds element to the appropriate list at
the given index where the head node is at index 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 The method returns true if the item is added and false otherwise.
boolean removeItem 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.
boolean removeint index: removes the item located at position index
in List where the head node is at index 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.
boolean removeint index: removes the item located at position index
in List where the head node is at index 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.
int indexOfItem target: returns the index of the first occurrence of target if
any and returns if target is not in the list. Use equals method to search for target.
ItemA getint index: returns the item at position index in List
and returns null if index is less than or greater than the size of the list.
ItemB getint index: returns the item at position index in List
and returns null if index is less than or greater than the size of the list.
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