Worked Example 19.1 showed you how to find all words with five distinct vowels (which might occur
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 all words in which each vowel occurs exactly once.
Data from worked example 19.1.
Transcribed Image Text:
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:
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 100% (2 reviews)
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 the full answer
Answered By
Vincent Omondi
I am an extremely self-motivated person who firmly believes in his abilities. With high sensitivity to task and operating parameters, deadlines and keen on instructions, I deliver the best quality work for my clients. I handle tasks ranging from assignments to projects.
4.90+
109+ Reviews
314+ Question Solved
Related Book For
Question Posted:
Students also viewed these Java Programming questions
-
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...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Using an approach similar to that in Worked Example 19.1, find all words with length of at least ten in which no letter is repeated. What is the longest one? How many such words exist for each...
-
Prove the famous (your name) uncertainty principle, relating the uncertainty in position (A = x) to the uncertainty in energy For stationary states this doesnt tell you muchwhy not? (B = p/2m + V):
-
Helium gas is compressed steadily from 90 kPa and 25C to 600 kPa at a rate of 2 kg/min by an adiabatic compressor. If the compressor consumes 70 kW of power while operating, the isentropic efficiency...
-
Hydra Aire, Inc., sells appliances to Seasons Department Store. A recent order requires Hydra Aire to manufacture and deliver 500 toasters at a price of $100 per unit. Hydra Aires manu facturing...
-
Give the slope and y-intercept for each of the lines defined in Exercise 11.9. LO9
-
The emergency room of the community hospital in Farmburg has a receptionist, one doctor, and one nurse. The emergency room opens at time zero, and patients begin to arrive sometime later. Patients...
-
Unheardof, Inc., has just paid a dividend of $5 per share. This dividend is anticipated to increase at a rate of 15% per year. If the cost of the equity for Unheardof is 25%, what should be the...
-
(a) Suppose you have two arrows of equal length on a tabletop. If you can move them to point in any direction but they must remain on the tabletop, how many distinct patterns are possible such that...
-
Perhaps the reason that so many movie titles start with the letter A is that their first word is A or An? Count how many movies in the data set of Worked Example 19.2 start with these words. Data...
-
Produce an infinite stream that contains the factorials 1!, 2!, 3!, and so on. Hint: First produce a stream containing arrays [1, 1!], [2, 2!], [3, 3!], and so on. Use BigInteger values for the...
-
Prout Company owns 80% of the common stock of Sexton Company. The stock was purchased for $1,600,000 on January 1, 2022, when Sexton Companys retained earnings were $800,000. On January 1, 2024,...
-
Micro-Brush requires a new component for their laptop cleaning machines. The company must decide whether to make or buy them. If it decides to make them. Should it use process A or process B? Use a...
-
Moving from a fee-for-service to a managed care delivery system set up a series of expectations (page 421). How many of these expectations are realistic? How many have been realized?
-
2. A 55 kg human is shot out the end of a cannon with a speed of 18 m/s at an angle of 60. Ignore friction and solve this problem with energy conservation. As he exits the cannon, find: a. horizontal...
-
Theoretical Background: Information Assurance (IA) architecture also known as security architecture is about planning, integrating and continually monitoring the resources of an organization so they...
-
AZCN recommends Microsoft Lens or Adobe Scan; download one of these to yo phone via your phone's app store 2. Place the document you want to scan on a flat, well-lit surface. Make sure the document...
-
Assume that the quantity theory of money holds and that velocity is constant at 5.0. Output is fixed at its full-employment value of 10 000, and the price level is 2.0. a. Determine the real demand...
-
Which of the companies has the lowest accounts receivable turnover in the year 20X2? a. Company A. b. Company B. c. Company C. d. CompanyD. 20X1 20X2 Credit Sales Average Receivables Balance $1.0...
-
What is a method? What is a message? How do messages relate to methods?
-
What are relationships called in UML?
-
What is a visibility symbol in UML?
-
Slow Roll Drum Co. is evaluating the extension of credit to a new group of customers. Although these customers will provide $198,000 in additional credit sales, 13 percent are likely to be...
-
Wendell's Donut Shoppe is investigating the purchase of a new $39,600 conut-making machine. The new machine would permit the company to reduce the amount of part-time help needed, at a cost savings...
-
1.Discuss the challenges faced with Valuing Stocks and Bonds. As part of this discussion, how will the selected item be implemented in an organization and its significance? 2. Discuss how Valuing...
Study smarter with the SolutionInn App