Question: For even more BONUS points, implement another generic class called SortableArray This class will have exactly the same functionality as the SortableArrayList class however it

 For even more BONUS points, implement another generic class called SortableArray

For even more BONUS points, implement another generic class called SortableArray This class will have exactly the same functionality as the SortableArrayList class however it will use a static array to store it's values instead of an ArrayList This means there will be a few changes: The constructor will have to take in a size for the array There is another change that must be done inside the constructor Without going into detail here (I will in class), Java "erases" all generic type information after compilation. This means that creating dynamic memory (memory created at runtime) is not possible using generics since the runtime environment (which is JVM) has no way of knowing what type to allocation and therefore it can't know how much memory to allocate. The best we can do here is to create an array of Java Object class types and then cast it to our generic type array. The casting should be checked at compile time while the dynamic memory allocation is done at runtime with the known type of Object. Your add method should be changed to a set method that takes in two parameters, an index and a value to insert at that index Make sure you validate the index. No index can be less than 0 or go past the boundaries of that static array The sort method implementation must also change a little The print method can stay the same, as an enhanced for loop can work with both a static array as well as a dynamic ArrayList object The Comparer interface should also stay the same Now in your Main class inside the main method, add code to create a SortableArray object and add 5 numbers to it, then call the sort method and then call the print method Both lists of numbers should print out when you run your program Be sure to add a newline in between printing the list, such that the first list prints out using the SortableArrayList object, then we have a newline, and then the second list prints out using the SortableArray object

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!