Question
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.
- The nondestructive methods shouldn't modify the list they're given; they should make a new ArrayList with the correct elements and return that.
- The destructive methods, on the other hand, should actually change the ArrayLists they're given, and then return them.
- 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.
- 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.
- 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.
- Doing above again, but with a different Predicate. Again, use a lambda expression for the Predicate
Examle output is shown below
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started