Question: Worked Example 19.1 showed you how to find all words with five distinct vowels (which might occur more than once). Using a similar approach, find

Worked Example 19.1 showed you how to find all words with five distinct vowels

(which might occur more than once). Using a similar approach, find all words in which each vowel occurs exactly once.

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 vilg ther imagi Step 3 Transform the stream. 7zle iStock.com/tigermad. try (Stream- lines = Files. lines (Paths.get("words.txt"))) { every lopr kuo 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.44 Rating (154 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

It appears that the worked example youve provided shows how to find words with all five vowels present potentially repeating using Java streams To fin... 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!