Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please tell me how to make this program, JAVA (Please include comments if it's possible, it would be helpful) I'd like to make it use

Please tell me how to make this program, JAVA

(Please include comments if it's possible, it would be helpful)

I'd like to make it use below 2 functional interfaces to implement helpful methods that take and change lists of integers

@FunctionalInterface

public interface Preficate{

boolean test (int t);

}

@FunctionalInterface

public interface Function {

int apply (int t);

}

Make a class ArrayListProfessor. It's a helper class that acts as a container for 4 static methods

  • destructiveFilter(ArrayList a, Predicate p)
  • nondestructiveFilter(ArrayList a, Predicate p)
  • nondestructiveFunctionApplyer(ArrayList a, Function f)
  • destructiveFunctionApplyer(ArrayList a, Function f)

All 4 of these static methods take an ArrayList of integers and either a Predicate or a Function. and all 4 of these methods should return an ArrayList of integers.

  1. The nondestructive methods shouldn't modify the list they're given; they should make a new ArrayList with the correct elements and return that.
  2. The destructive methods, on the other hand, should actually change the ArrayLists they're given, and then return them.
  3. The filter methods should apply the Predicate they're given to each element in the list, and whether the Predicate returns true or false determines whether that element will be in the list that's returned.
  4. The functionApplyer methods should apply the Function they're given to each element in the list, and put each result at the same index in the list.

Tester.jave main method should do:

Randomly make ArrayLists of length 10, with elements beteween 1 and 1000, as needed.

  1. Test and print the input and output of destructiveFilter and nonDestructiveFiler on the lists for a particular Predicate. Use a lambda expression for the Predicate.
  2. Doing above again, but with a different Predicate. Again, use a lambda expression for the Predicate

Examle output is shown below

image text in transcribed
Tester: intList: [743, 957, 688, 41, 378, 318, 359, 472, 751, 210] intList non-destructively filtered to remove odds: [688, 378, 318, 472, 210] intList (should be unchanged): [743, 957, 688, 41, 378, 318, 359, 472, 751, 210] intList destructively filtered to remove odds. .. intList: [688, 378, 318, 472, 210] intList2: [991, 741, 427, 438, 81, 290, 996, 172, 484, 684] intList2 non-destructively filtered to remove numbs greater than 500: [427, 438, 81, 290, 172, 484] intList2 (should be unchanged) : [991, 741, 427, 438, 81, 290, 996, 172, 484, 684] intList2 destructively filtered to remove nums greater than 500. .. intList2: [427, 438, 81, 290, 172, 484] intList3: [807, 210, 808, 152, 28, 593, 433, 729, 950, 818] intList3 non-destructively made all values into their squares: [651249, 44100, 652864, 23104, 784, 351649, 187489, 531441, 902500, 669124] intList3 (should be unchanged) : [807, 210, 808, 152, 28, 593, 433, 729, 950, 818] intList3 destructively made all values into their squares... intList3: [651249, 44100, 652864, 23104, 784, 351649, 187489, 531441, 902500, 669124] intList4: [354, 75, 84, 651, 402, 702, 883, 322, 868, 370] intList4 non-destructively made all values decremented: [353, 74, 83, 650, 401, 701, 882, 321, 867, 369] intList4 (should be unchanged) : [354, 75, 84, 651, 402, 702, 883, 322, 868, 370] intList4 destructively made all values decremented... intList4: [353, 74, 83, 650, 401, 701, 882, 321, 867, 369]

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions