Question
JAVA Higher Order Functions and Lists Now that weve looked under the hood and understand the theory of recursive data structures, well move on to
JAVA Higher Order Functions and Lists
Now that weve "looked under the hood" and understand the theory of recursive data structures, well move on to utilizing the Java (generic) implementation of these collections, along with higher-order functions. A higher order function is a function that takes another function as one of its arguments. The higher order function then executes the given function as part of its implementation. Examples include: fold (aka reduce), producing a single summary value from a collection of items (e.g. count()); filter, returning a subset of items (e.g., books published before 2000); and map, producing corresponding items by performing an operation on each original item (e.g., the titles of the books).
Part 1:
Start by re-implementing your Words in a Sentence solution with List
-
Write a method that counts and returns the number of punctuation in a given sentence. Express this as a higher-order function and implement it.
-
Write a method that counts and returns the number of words in the sentence that have the letter z in them. Express this as a higher-order function and implement it.
Write tests for both methods. When calling these methods, try to express the functions you pass to them in lambda function notation.
Part 2:
If you recently ate at Chipotle, you may have received a brown paper bag with gibberish letters written on it: AKINGMAY AWAY IGPAY EALDAY ABOUTWAY IGPAY ATINLAY. In fact this message is written in Piglatin, a simple but fictitious language.
Piglatin converts a word in English using the following two rules:
-
If the letter begins with a vowel, then WAY is appended to the word.
-
If the letter begins with a consonant (a letter other than a vowel), then the first letter of the word is moved to the end, and then AY is appended to it.
-
Using these rules, one can decode the Chipotle message to MAKING A PIG DEAL ABOUT PIG LATIN.
-
Write a method that codes and returns an English sentence in Piglatin.
Write tests for this method.
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