Question: : We will create a class similar to ArrayList, we will call it mylist. 1. Create a generic class MyList that has an array of

: We will create a class similar to ArrayList, we will call it mylist.

1. Create a generic class MyList that has an array of generic type, create private int variable (count) that indicates how many elements currently in the array.

2. Add no-parameter constructor that creates the array with 10 elements as the default size.

3. Add parameter constructor that creates the array with size that input as a parameter.

4. Add method size( ) that returns how many elements currently in the list.

5. Add method isEmpty() that returns true when the list is empty, otherwise it returns true.

6. Add method add(E e) (void) that adds the element e at the end of the array if it is not null. If the array is full, create a new array with double size of the old one, copy the elements to the new one, and make the reference points to the new one.

7. Method clear ( ): void method that removes all elements in the list.

8. Method get( int i): it return the element at position i if there is an element, otherwise throws an exception.

9. Method display (void) that prints the elements currently in the list. A

10. Create Test class with main method, and create two objects of MyList, each one initially contains 3 elements: one of type Integer and the other one of type Character. Test the methods above.

Add the following methods :

11. Method set(int i, E e): void method that replaces element at position i with e if there is an element at i, otherwise it throws an exception.

12. Method contains(E e): it returns true if the element in the list, otherwise it returns false.

13. Method indexOf(E e): it returns the index of the element e in the list, otherwise it returns -1.

14. Method toArray( ): it returns an array of all elements in the list.

15. Method remove( int i): it removes the element at the specified position in this list. Shifts any subsequent elements to the left (subtracts one from their indices). It returns the removed element. If the index is out of range, it throws an exception.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!