Question: CSCI 282 Lab 10 Purpose: This lab will be used as bonus but please still take it seriously. This goes over some advanced Java concepts
CSCI 282 Lab 10 Purpose: This lab will be used as bonus but please still take it seriously. This goes over some advanced Java concepts that will definitely strengthen you as Java T two main concepts in this developer. lab Generics (both using and creating your own Generic classes) and Lambda functions (which were introduced in Java 8, the latest version of Java). Directions: Use Eclipse Make a generic class called SortableArrayList that has a single generic type parameter This class will have an ArrayList field that will store our items o It will have an add method that just adds an item to the o It will have a print method that uses an enhanced for loop to iterate over all elements and print them out with commas separating the elements It will also have an inner interface that will be used later on This interface will be called comparer and it will be a generic interface with the same type parameter as the SortableArrayList class This interface will contain a single method called greatermhan that returns a boolean and takes in two parameters, both of the generic type When implemented, it will be used to compare the two parameters and return true if parameter 1 is larger than parameter 2 or false otherwise o Finally, this class will have a sort method. This method doesn't return anything It takes in an object of our Comparer interface type The parameter can be called comparer (with a lowercase c) This method will sort all the elements in the ArrayList field by using the comparer object it receives Here is the algorithm for the sort method (this assumes the ArrayList field is called list, the parameter is called comparer, and the generic type parameter is called T) if size of list is less than or equal to 1 then return, nothing to do since list isn't big enough end if loop x 0 to size of list. loop i 0 to size of list minus i if compa rer greater Than (list [i], list 11) then swap list [i] and list [i+1] end if end loop end loop
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
