Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please follow the comments throughout this code. Use the driver class supplied and follow the instructions in the comments. import java.util. function. *; import java.util.ArrayList;

Please follow the comments throughout this code.

Use the driver class supplied and follow the instructions in the comments.

image text in transcribedimage text in transcribed

import java.util. function. *; import java.util.ArrayList; public class Driver { public static void main(String[] args) { ArrayList words = new ArrayList(); words.add("interface"); words.add("class"); words.add("inheritance"); words.add("abstract"); 1/this call to repeat passes a lambda and prints a line of 10 # symbols repeat (10, () -> System.out.print("#")); I/Write a call to repeat that prints the phrase "Lambdas ar fun!" 5 times, one per line //The Consumer first prints the first character of the input string Consumer first = inString -> System.out.print(inString.charAt(0)); first.accept("Java"); 1/Create a Consumer that prints the last character of the input string //Call the accept method 1/Create a Consumer that prints the first five characters of a String or the entire string if length less than five I/Hint: Use the ternary operator //Call accept I/Create a Function that accepts an Integer argument and returns the square of that Integer //Call apply 1/Create a Function that takes an Integer argument and returns the negative of the argument 17 call apply //Now use the default andThen method of Function to square an integer and then negate it 1/Hint: Use your square method to call andThen passing the negate method which calls apply 1/Create a BiFunction that takes two Double arguments and returns the first argument raised to the power of the second //call apply //Create a BiPredicate that accepts two String arguments and returns true if they are the same length //Call test 1/Create a BiPredicate that accepts two String arguments and returns true if they start with the same character //Call test //Now use the default and method of BiPredicate to test if two strings are the same length and start with the same character //Now use the default or method of BiPredicate to test if two strings are the same length or start with the same character //Create a Comparator to compare strings by length (short to long) //Hint: subtract the lengths //Now call Collections. sort to sort the supplied array by string length //call the forEach method of the ArrayList class and pass an appropriate lambda to print each word in the supllied list I/Hint: The lambda must be a Consumer } private static void repeat(int n, Runnable action) { for (int i = 0; i<>

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

Database Systems A Practical Approach To Design Implementation And Management

Authors: THOMAS CONNOLLY

6th Edition

9353438918, 978-9353438913

More Books

Students also viewed these Databases questions