Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write a Java code for this (Please do not copy from other experts) Please write a class named MySortedList that provides an implementation of

Please write a Java code for this (Please do not copy from other experts)

Please write a class named MySortedList that provides an implementation of the interface below. Make sure not to use any raw types. Please do not include any IMPORT statements or javadoc comments with answer.

Please finish as soon as possible Thank you

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

type parameter in comments in your response. And, int size(); void clear(); int findInsertionIndex ( T element); void insert(int index, T element) throws IndexoutofBounds Exception, IllegalArgumentException; void insert( T element) throws IllegalArgumentException; int findFirstoccurrenceIndex ( T element); T remove(int index) throws IndexOutofBounds Exception; T remove(T element) throws IllegalArgumentException, NoSuchElementException; detailed below to maximize code reuse and make the best use of The MySortedList class must have ONE private array that is used to store the elements of the list in ascending_(i.e. least-to-greatest) order. - IMPORTANT: Duplicate elements are allowed in this SortedList. You can choose where to insert the duplicate element as long as it is contiguous (i.e. grouped with) with the other duplicates already present in the list. This class must also have a single, no-argument constructor that creates the generic array of type T with an initial length of 10. No other constructors should be written. The MySortedList class should also have a nested inner class named MySortedListlterator that satisfies the requirements of the Iterator T interface. The iterator should iterate over the elements - returns number of elements currently in the sorted list - HINT: the size of the sorted list isn't the same as the length of the backing array. You'll want to keep track of the logical size of the collection using a private field. void ctear() - Empties the sorted list of all elements. - All elements of the backing array should be reset to null - The size of the sorted list should be reset to zero - Finds and returns the integer index where the element can be inserted while keeping the list in sorted order. The sorted order must be ascending (i.e. least-to-greatest). - REMEMBER: parameterized type T is bounded to guarantee that the elements implement the compareTo(T) method. When comparing, remember that foo.compareTo(bar) will return: - a negative result when foo should be placed before bar - a positive result when foo should be placed after bar - a result of zero when foo and bar are equal void insert(int index, T element) throws IndexOutofBounds Exception, IMlegalArgumentException - Inserts an element at the specified position in the sorted list, where index. O represents the first position in the sorted list. Remaining elements should be shifted towards the end of the sorted list (see diagram). must first be increased in size using the following method which you can assume exists: - MyArrayUtils.doubleLength(T[] arr); // returns a T[] that contains a deep copy of the elements of the T[] arr that is passed in. The returned array will have double the length of the array - method throws IndexOutOfBoundsException when the index is invalid. The message should contain text describing the specific reason the index is invalid. An index is invalid if: - the value of the index is negative - the value of the index exceeds the size of the sorted list. - Inserts an element into the sorted list while maintaining the ordering of the list. This method MUST use the insert(int, T) method to perform the insertion! - HINT: the implementation of this method is nearly trivial if you've implemented the findinsertionlndex(T) and insert(int, T ) methods! Finds and returns the integer index of the first occurrence of an element in the sorted list that is equal to the element passed in. REMEMBER: parameterized type T is bounded to guarantee that the elements implement the compareTo(T) method. When comparing, remember that foo.compareTo(bar) will return a result of zero when foo and bar are equal. Do not assume that an equals() method has been written for type T. T remove(int index) throws IndexOutofBoundsException Removes and returns the element at the specified position in the jorted list, where index 0 represents the first element to be removed. Remaining elements should be shifted towards the beginning of the sorted list (see diagram). method throws IndexOutOfBoundsException when the incex is valid. The message should contain text describing the specific reason the index is invalid. An index is invalid if: - the value of the index is negative - the value of the index does not point to an element that exists within the sorted list. T remove(t eIement) throws IIIegolargumentexception, RaSuchelealentexcepti - Removes and returns the first occurrence of an element in the sorted list that is equal to the element passed in. Remaining elements should be shifted towards the beginning of the sorted fist (see diagram). This method MUST use the remove(int index) method to perform the removal? argument is null. The message should contain text describing the reason the argument is illegal. - You may assume that llegalArgu hentException is an unchecked exception and the resenting the message. constructor that takes in a single String parameter representing the message. - method throws within the list. - You may assume that NoSuchElementException is an unchecked exception and has a constructor that takes in a single String parameter representing the message. type parameter in comments in your response. And, int size(); void clear(); int findInsertionIndex ( T element); void insert(int index, T element) throws IndexoutofBounds Exception, IllegalArgumentException; void insert( T element) throws IllegalArgumentException; int findFirstoccurrenceIndex ( T element); T remove(int index) throws IndexOutofBounds Exception; T remove(T element) throws IllegalArgumentException, NoSuchElementException; detailed below to maximize code reuse and make the best use of The MySortedList class must have ONE private array that is used to store the elements of the list in ascending_(i.e. least-to-greatest) order. - IMPORTANT: Duplicate elements are allowed in this SortedList. You can choose where to insert the duplicate element as long as it is contiguous (i.e. grouped with) with the other duplicates already present in the list. This class must also have a single, no-argument constructor that creates the generic array of type T with an initial length of 10. No other constructors should be written. The MySortedList class should also have a nested inner class named MySortedListlterator that satisfies the requirements of the Iterator T interface. The iterator should iterate over the elements - returns number of elements currently in the sorted list - HINT: the size of the sorted list isn't the same as the length of the backing array. You'll want to keep track of the logical size of the collection using a private field. void ctear() - Empties the sorted list of all elements. - All elements of the backing array should be reset to null - The size of the sorted list should be reset to zero - Finds and returns the integer index where the element can be inserted while keeping the list in sorted order. The sorted order must be ascending (i.e. least-to-greatest). - REMEMBER: parameterized type T is bounded to guarantee that the elements implement the compareTo(T) method. When comparing, remember that foo.compareTo(bar) will return: - a negative result when foo should be placed before bar - a positive result when foo should be placed after bar - a result of zero when foo and bar are equal void insert(int index, T element) throws IndexOutofBounds Exception, IMlegalArgumentException - Inserts an element at the specified position in the sorted list, where index. O represents the first position in the sorted list. Remaining elements should be shifted towards the end of the sorted list (see diagram). must first be increased in size using the following method which you can assume exists: - MyArrayUtils.doubleLength(T[] arr); // returns a T[] that contains a deep copy of the elements of the T[] arr that is passed in. The returned array will have double the length of the array - method throws IndexOutOfBoundsException when the index is invalid. The message should contain text describing the specific reason the index is invalid. An index is invalid if: - the value of the index is negative - the value of the index exceeds the size of the sorted list. - Inserts an element into the sorted list while maintaining the ordering of the list. This method MUST use the insert(int, T) method to perform the insertion! - HINT: the implementation of this method is nearly trivial if you've implemented the findinsertionlndex(T) and insert(int, T ) methods! Finds and returns the integer index of the first occurrence of an element in the sorted list that is equal to the element passed in. REMEMBER: parameterized type T is bounded to guarantee that the elements implement the compareTo(T) method. When comparing, remember that foo.compareTo(bar) will return a result of zero when foo and bar are equal. Do not assume that an equals() method has been written for type T. T remove(int index) throws IndexOutofBoundsException Removes and returns the element at the specified position in the jorted list, where index 0 represents the first element to be removed. Remaining elements should be shifted towards the beginning of the sorted list (see diagram). method throws IndexOutOfBoundsException when the incex is valid. The message should contain text describing the specific reason the index is invalid. An index is invalid if: - the value of the index is negative - the value of the index does not point to an element that exists within the sorted list. T remove(t eIement) throws IIIegolargumentexception, RaSuchelealentexcepti - Removes and returns the first occurrence of an element in the sorted list that is equal to the element passed in. Remaining elements should be shifted towards the beginning of the sorted fist (see diagram). This method MUST use the remove(int index) method to perform the removal? argument is null. The message should contain text describing the reason the argument is illegal. - You may assume that llegalArgu hentException is an unchecked exception and the resenting the message. constructor that takes in a single String parameter representing the message. - method throws within the list. - You may assume that NoSuchElementException is an unchecked exception and has a constructor that takes in a single String parameter representing the message

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

Database Application Development And Design

Authors: Michael V. Mannino

1st Edition

0072463678, 978-0072463675

More Books

Students also viewed these Databases questions

Question

How are savers hurt and borrowers helped by inflation?

Answered: 1 week ago

Question

Describe the patterns of business communication.

Answered: 1 week ago

Question

3. Provide two explanations for the effects of mass media

Answered: 1 week ago