Question: Using an approach similar to that in Worked Example 19.1, find all words with exactly one vowel (which might be repeated). What is the longest

Using an approach similar to that in Worked Example 19.1, find all words with exactly one vowel (which might be repeated). What is the longest one? How many such words exist for each length?

Data from worked example 19.1.

WORKED EXAMPLE 19.1 Word Propertles It is fun to find words with

interesting properties. To see how streams make this easy, locate the code

for Worked Example 19.1 in the companion code for this book. Problem

WORKED EXAMPLE 19.1 Word Propertles It is fun to find words with interesting properties. To see how streams make this easy, locate the code for Worked Example 19.1 in the companion code for this book. Problem Statement The French word oiseau has five distinct vowels, which is pretty nifty. Are there English words like that? Just a few or a lot? Which words are the shortest and longest among them? Step 1 Get the data. Step 2 Make a stream. compose DILA electric masterpiece ther imagi vilg Step 3 Transform the stream. 7zle iStock.com/tigermad. try (Stream- lines = Files. lines (Paths.get("words.txt"))) { every lopr kno In this case, we need a list of English words. The companion code for this book contains a copy of the words.txt file that is available on computers with a Unix-based operating system. bove In this case, it is very easy to get a stream of words because the input file has one word per line. Simply call balar First, the input contains many words ending with's, such as Alice's. We don't want them: try (Stream- lines = Files. lines (Paths.get("words.txt"))) { Stream words = lines.filter(w -> !w.endsWith("'s")); return word.toLowerCase().codePoints() // A stream of code points filter (c => c == 'a' || c= 'e' || c= '1' || c='0' || c == 'u') .distinct() // The distinct vowels in word .count() == 5; } And we only want words that have all five vowels. This is complex enough that we should write a separate method public static boolean has Five Vowels (String word) This method needs to check whether the word contains all five vowels. As an aside, this too can be done with streams:

Step by Step Solution

3.47 Rating (160 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To find all words with exactly one vowel which might be repeated we can modify the code example that youve provided The original code from Worked Exam... View full answer

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 Java Programming Questions!