Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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(you can use the Java LinkedList implementation). As before, this list represents a sentence. Add the following operations to your re-factored solution.

  1. 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.

  2. 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:

  1. If the letter begins with a vowel, then WAY is appended to the word.

  2. 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.

  1. 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

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What does ESP add to the IP packet?

Answered: 1 week ago