Question: 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

 This lab will be used as bonus but please still take

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 a Java developer. The two main concepts In this lab are 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 mat has a single generic type parameter This class will have an Arraylist field that will store our items It will have an add method that just adds an item to the Arraylist field 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 interlace with the same type parameter as the SortableArraylist class This interface will contain a single method called greaterThan 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 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;/othing 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 comparer.greaterThan

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!