Question: I need help with this Java question. Please provide the final code and output if possible. Part 1: More FancyArray methods Add the following instance

I need help with this Java question. Please provide the final code and output if possible.

Part 1: More FancyArray methods

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.

A method named forEach that takes a Consumer 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 8 4 5 .

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]

A method named max that takes a Comparator and finds the maximum element in the FancyArray based on the comparator. Assume that the FancyArray isnt empty.

A method named sort that takes a Comparator and sorts the FancyArray on the basis of the comparator, using the selection sort algorithm.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!