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% (QA)
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...
-
Compare Javas packages with Rubys modules.
-
Consider the following cash flow profile and assume MARR is 10 percent/year. a. Determine the ERR for this project. b. Is this project economically attractive? EOY 0 2 3 4 5 6 NCF -$100 $15 $15 $15...
-
Maese Industries Inc. has warrants outstanding that permit the holders to purchase 1 share of stock per warrant at a price of $25. a. Calculate the exercise value of the firms warrants if the common...
-
The security professional needs to be aware of the important security concepts that apply during software development and in the production environment. Which command in data control language...
-
Garden Glory Project Questions Assume that Garden Glory designs a database with the following tables: OWNER (OwnerID, OwnerName, OwnerEmail, OwnerType) OWNED_PROPERTY (PropertyID, PropertyName,...
-
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...
-
A beam of radioactive particles is measured as it shoots through the laboratory. It is found that, on the average, each particle lives for a time of 2.0 10 -8 s; after that time, the particle...
-
What is stand-alone risk?
-
What is the inpatient prospective payment system (IPPS), and how does it work?
-
What is cost shifting?
-
What reimbursement methodology is unique to managed care plans?
-
What are the tax advantages to purchasers of preferred stock?
-
List six drawbacks of using only subjective information in formulating strategies.
-
Explain the term global capital markets. This chapter primarily discusses global equity markets. What other types of financial instruments are traded in these markets? How important are global...
-
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?
-
Prepare for an audit. Examine the types of source information needed during an audit. Audit sampling detail Audio-visual information Checklists
-
Ethics is inherently part of business. Analyse the concept of amoral managers as opposed to the factors which relate to the relationships and interwoven alliance between ethics and business.
-
Consider the politics of law enforcement related to terrorism and homeland security. What do you believe the future holds for law enforcement in these areas? How do you see policing changing? Should...
Study smarter with the SolutionInn App