Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

6th Edition

1943153035, 978-1943153039

More Books

Students also viewed these Databases questions