Please help as List Methods In this part of the assignment, you'll write several generic List methods
Fantastic news! We've Found the answer you've been seeking!
Question:
Please help as
Transcribed Image Text:
List Methods In this part of the assignment, you'll write several generic List methods that make use of the Comparator interface. Write these all in a class named CompareLists in CompareLists.java. 1. Write a generic method minimum that takes a List<E> and a Comparator<E> and returns the smallest element in the list according the comparator, or null if the list is empty. Assume there are no null elements in the list. 2. Write an overload of the generic method minimum that takes an E[] (an array of E) and a Comparator<E> and returns the smallest element in the array according the comparator, or null if the array is empty. Assume there are no null elements in the array. 3. Write a generic method greater Than that takes a List<E>, a Comparator<E>, and an element E, and returns a new List<E> containing just the elements that are larger than the given element according to the given comparator. Assume there are no null elements in the array. 4. Write a generic method inOrder that takes a List<E> and a Comparator<E> and returns true if the elements in the array list are in increasing order according to the comparator, and false otherwise. If any of the elements in the list are null, throw an IllegalArgumentException with a message that says "null value in list". 5. Write an overload of the generic method in0rder that takes an E[] (an array of E) and a Comparator<E> and returns true if the elements in the array list are in increasing order according to the comparator, and false otherwise. If any of the elements in the list are null, throw an IllegalArgumentException with a message that says "null value in array". 6. Write a generic method merge that takes a Comparator<E> and two List<E>, each of which is in increasing order according to the given comparator. It should return a new List<E> containing all the elements from both lists in increasing order. If any of the elements in either list are null, throw an IllegalArgumentException with a message that says "null value in first list" if it came from the first one, and "null value in second list" if it came from the second one. Hint: write and tes method at a time! List Methods In this part of the assignment, you'll write several generic List methods that make use of the Comparator interface. Write these all in a class named CompareLists in CompareLists.java. 1. Write a generic method minimum that takes a List<E> and a Comparator<E> and returns the smallest element in the list according the comparator, or null if the list is empty. Assume there are no null elements in the list. 2. Write an overload of the generic method minimum that takes an E[] (an array of E) and a Comparator<E> and returns the smallest element in the array according the comparator, or null if the array is empty. Assume there are no null elements in the array. 3. Write a generic method greater Than that takes a List<E>, a Comparator<E>, and an element E, and returns a new List<E> containing just the elements that are larger than the given element according to the given comparator. Assume there are no null elements in the array. 4. Write a generic method inOrder that takes a List<E> and a Comparator<E> and returns true if the elements in the array list are in increasing order according to the comparator, and false otherwise. If any of the elements in the list are null, throw an IllegalArgumentException with a message that says "null value in list". 5. Write an overload of the generic method in0rder that takes an E[] (an array of E) and a Comparator<E> and returns true if the elements in the array list are in increasing order according to the comparator, and false otherwise. If any of the elements in the list are null, throw an IllegalArgumentException with a message that says "null value in array". 6. Write a generic method merge that takes a Comparator<E> and two List<E>, each of which is in increasing order according to the given comparator. It should return a new List<E> containing all the elements from both lists in increasing order. If any of the elements in either list are null, throw an IllegalArgumentException with a message that says "null value in first list" if it came from the first one, and "null value in second list" if it came from the second one. Hint: write and tes method at a time!
Expert Answer:
Answer rating: 100% (QA)
All the methods has been written as per requirement Code import javautil class CompareLists public E ... View the full answer
Related Book For
Microeconomics An Intuitive Approach with Calculus
ISBN: 978-0538453257
1st edition
Authors: Thomas Nechyba
Posted Date:
Students also viewed these electrical engineering questions
-
Economics Hi please help me this statement thanks Hi please help me to answer this statement on below question, you dont have to show your work (in this case the decision tre
-
Factors impacting employee absenteeism and the managers perception of its causes in the hotel industry The economic viability and success of a hotel depend on the optimisation of all resources,...
-
Q1 Combustion of ethanol. The "Lewis Structure" of the molecule ethanol is presented in Figure Q1.1. How many electron bonding pairs and electron lone pairs are present in the molecule? How many...
-
In the dynamic and expanding urban environment of "Slothsberg", a new highway ("Snailpace Highway") is to be constructed over the existing "Dillydally Highway". The following conditions apply to the...
-
Select the better of two proposals to improve street safety and lighting in a colonia in south central New Mexico. Use a B/C analysis and an interest rate of 8% peryear. Proposal 1 Proposal 2 Initial...
-
Examine the following program: class Exercise1 { public static void main (String[] args ) { int[] val = {0, 1, 2, 3}; sum = System.out.println( "Sum of all numbers = " + sum ); } } Complete the...
-
What is the term used to describe an unsecured bond? a. Debenture bond b. Mortgage bond c. Serial bond d. Callable bond
-
PowerTrain Sports Inc. manufactures and sells two styles of All Terrain Vehicles (ATVs), the Mountain Monster, and Desert Dragon from a single manufacturing facility. The manufacturing facility...
-
Suppose that a system consists of four subsystems. For the baseline configuration, the system will fail if each subsystem fails. The reliability data of each unit that comprise each subsystem in the...
-
Major Project - Andrew Best - Best Business Solutions Incorporated (BBSI) Andrew Best was a very inquisitive child growing up. He was a great student in school and always asked a lot of questions....
-
Brian, a self emploed individual, pays state income tax payments of: $900 on January 15, 2019 (4th estimated tax payment for 2018) $1000 on April 16, 2019 (1st estimated tax payment in 2019) $1000 on...
-
Discuss the thermodynamic principles governing the separation of azeotropic mixtures using advanced distillation techniques such as pressure swing distillation, extractive distillation, and hybrid...
-
Explore the application of thermodynamic analysis to environmental and ecological systems, addressing concepts such as energy flow, entropy production, and emergent behaviors in ecosystems, and their...
-
Bartholemew Incorporated uses a job-order costing system and its total manufacturing overhead applied always equals its total manufacturing overhead. In February the company completed job G43C that...
-
A positive charge q = 2.60 C on a frictionless horizontal surface is attached to a spring of force constant k as in the figure shown below. When a charge of 42 = -8.350 C is placed 9.50 cm away from...
-
Suppose the economy has the following consumption pattern Sandwich Hotdog Cell phone Super car 2019 Price $7 $3 $200 $5,000 Quantity 500 400 100 3 2020 Price $10 $5 $250 $7,000 Quantity 200 400 100 2...
-
Describe how institutional changes (there are two we talked about and are also mentioned in the text) in the U.S. labor market have affected wage inequality since the 1980s. Between what groups did...
-
Assume you are the accountant for Catalina Industries. John Catalina, the owner of the company, is in a hurry to receive the financial statements for the year ended December 31, 20X1, and asks you...
-
Consider a sequential game which is known as the Centipede Game. In this game, each of two players chooses between Left and Right each time he or she gets a turn. The game does not, however,...
-
I have two 5-year old girls Ellie and Jenny at home. Suppose I begin the day by giving each girl 10 toy cars and 10 princess toys. I then ask them to plot their indifference curves that contain...
-
Fishing in the Commons: In the text, we introduced the notion of the Tragedy of the Commons and found its source in the emergence of externalities when property rights are not well established. This...
-
In some speed ranges, vortices are shed from the rear of bluff cylinders placed across a flow. The vortices alternately leave the top and bottom of the cylinder, as shown, causing an alternating...
-
On a cruise ship, passengers complain about the amount of smoke that becomes entrained behind the cylindrical smoke stack. You have been hired to study the flow pattern around the stack, and have...
-
A 1:8 scale model of a tractor-trailer rig is tested in a pressurized wind tunnel. The rig width, height, and length are \(W=0.305 \mathrm{~m}\), \(H=0.476 \mathrm{~m}\), and \(L=2.48 \mathrm{~m}\),...
Study smarter with the SolutionInn App