Question: Objective: Generics Create a container class called StrangeContainer that stores generic objects that implement the java.util.Comparable interface. Use an ArrayList as your underlying storage structure.

 Objective: Generics Create a container class called StrangeContainer that stores generic

Objective: Generics Create a container class called StrangeContainer that stores generic objects that implement the java.util.Comparable interface. Use an ArrayList as your underlying storage structure. StrangeContainer has the following methods 1. An add method that always adds an element to the begining/head of this container 2. A delete method that always removes the middle element in the container where middle is defined as size/2 in Java, with size being the current number of elements in the container. Remaining elements are shifted up, if necessary, after a deletion. The delete method should return the element being deleted. 3. A peek method that retrieves an element at a particular index in the container; this 4. Asort method that sorts all the elements in the container, using the compareTo method 5. Asize method that gives the current number of elements in the container element is not deleted or altered in any way for comparisons. Use the Collections.sort method to perform the sorting. 6. AtoString method that prints out its elements in the format "[elemente, element?, ..., elementn]" Finally, write a Driver class to test your code, demonstrating all methods with a StrangeContainer of Integer objects Have your driver implement the statement sequence below: .Create an empty StrangeContainer object . Add integers to the StrangeContainer in this sequence: 12, 22, 81, 52, 11, 3 and 4. .Call toString on this StrangeContainer. You should get [4, 3, 11, 52, 81, 22, 12] . Call size on this StrangeContainer. You should get 7 .Call peek (0)on this StrangeContainer. You should retrieve 4. .Call peek (6)on this StrangeContainer. You should retrieve 12. . Call delete() seven times on this StrangeContainer, calling toString every time after a deletion; you should delete elements in the following sequence: 52, 11, 22, 3, 12 and 4. Finally, recreate the StrangeContainer with elements 0-6 being [4, 3, 11, 52, 81, 22, 12]; then call sort(), followed by toString(). The StrangeContainer should have elements 0-6 as [3, 4, 11, 12, 22, 52, 81] 81

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!