Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need help with this Java question. Please provide in Java, the code and output if possible. Add the following instance methods to the FancyArray
I need help with this Java question. Please provide in Java, the code and output if possible.
Add the following instance methods to the FancyArray class from Homework 3. Do not use an ArrayList, List, or any kind of collection in these methods. 1. A method named forEach that takes a Consumer super E> and performs its action for each element of the FancyArray. For example, if fa is a FancyArray> representing [8,4,5], and Consumer c=e> System.out.print (e+ " ), then fa.forEach(c) should print 845 . 2. A method named replaceAll that takes a UnaryOperator and replaces each element of the FancyArray with the result of applying the operator to that element. For example, if fa is a FancyArray representing [8,4,5], and UnaryOperator> op =e>e+2 then, as a result of saying fa.replaceAll(op), fa should represent [10,6,7] 3. A method named max that takes a Comparator super E> and finds the maximum element in the FancyArray based on the comparator. Assume that the FancyArray isn't empty. 4. A method named sort that takes a Comparator and sorts the FancyArray on the basis of the comparator, using the selection sort algorithmStep 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