Question
***Sample Output ----jGRASP exec: java VowelWords Enter a sentence: There's no place like home! The number of words in userStr ending in vowels is: 5
***Sample Output
----jGRASP exec: java VowelWords Enter a sentence: There's no place like home! The number of words in userStr ending in vowels is: 5 The number of words in userStrArray ending in vowels is: 5 Enter a sentence (to stop, type exit): Show me the money! The number of words in userStr ending in vowels is: 2 The number of words in userStrArray ending in vowels is: 2 Enter a sentence (to stop, type exit): La-dee-da, LA-DEE-DA. The number of words in userStr ending in vowels is: 6 The number of words in userStrArray ending in vowels is: 6 Enter a sentence (to stop, type exit): exit The total number of words ending in vowels is: 13 Bye! ----jGRASP: operation complete.
----jGRASP exec: java VowelWords Enter a sentence: exit The number of words in userStr ending in vowels is: 0 The number of words in userStrArray ending in vowels is: 0 Enter a sentence (to stop, type exit): The number of words in userStr ending in vowels is: 0 The number of words in userStrArray ending in vowels is: 0 Enter a sentence (to stop, type exit): Hakuna Matata! What a wonderful phrase. The number of words in userStr ending in vowels is: 4 The number of words in userStrArray ending in vowels is: 4 Enter a sentence (to stop, type exit): Just keep swimming... The number of words in userStr ending in vowels is: 0 The number of words in userStrArray ending in vowels is: 0 Enter a sentence (to stop, type exit): exit The total number of words ending in vowels is: 4 Bye! ----jGRASP: operation complete.
----jGRASP exec: java VowelWords
Enter a sentence: The number of words in userStr ending in vowels is: 0 The number of words in userStrArray ending in vowels is: 0
Enter a sentence (to stop, type exit): 0 The number of words in userStr ending in vowels is: 0 The number of words in userStrArray ending in vowels is: 0 Enter a sentence (to stop, type exit): a The number of words in userStr ending in vowels is: 1 The number of words in userStrArray ending in vowels is: 1 Enter a sentence (to stop, type exit): aeiou The number of words in userStr ending in vowels is: 1 The number of words in userStrArray ending in vowels is: 1 Enter a sentence (to stop, type exit): ? The number of words in userStr ending in vowels is: 0 The number of words in userStrArray ending in vowels is: 0 Enter a sentence (to stop, type exit): ?a? The number of words in userStr ending in vowels is: 1 The number of words in userStrArray ending in vowels is: 1 Enter a sentence (to stop, type exit): a e i o u The number of words in userStr ending in vowels is: 5 The number of words in userStrArray ending in vowels is: 5 Enter a sentence (to stop, type exit): b? The number of words in userStr ending in vowels is: 0 The number of words in userStrArray ending in vowels is: 0 Enter a sentence (to stop, type exit): a1 b2 A1A The number of words in userStr ending in vowels is: 3 The number of words in userStrArray ending in vowels is: 3 Enter a sentence (to stop, type exit): exit The total number of words ending in vowels is: 11 Bye! ----jGRASP: operation complete.
*Write a program in Java to count the words that end in vowels in given sentences:
1. Prompt the user for one string: userStr.
2. Print the number of words ending in vowels.
- A vowel is at the end of a word if there is not an alphabetic letter immediately following it.
- The method Character.isLetter() tests if a character is an alphabetic letter (A-Z, a-z). E.g. Character.isLetter('a') is true and Character.isLetter('.') is false.
- See the sample output for examples.
3. Convert the String userStr to an array of characters called userStrArray.
- This step is just one line of code:
-- char[] userStrArray = userStr.toCharArray();
4. Repeat step 2, using the character array userStrArray instead of the String userStr, to count the number of words (in the array) ending in vowels.
- It will be the same number of words as the first one.
- Do not use userStr in step 4. Use only userStrArray.
- The goal is to practice using array syntax.
5. Ask the user for another string and, unless the string is "exit", repeat steps 2, 3, 4, 5.
- Steps 1, 2, 3, 4, 5 must execute at least once, even if the user enters "exit" for the first string.
- Only start checking for "exit" when the user enters the second string (and subsequent strings).
6. When the user enters "exit", display a message stating the total number of words ending in vowels (in all sentences combined).
**The goal is to compare the syntax for traversing a string to the syntax for traversing an array in Java; practice using loops, if statements, and switch statements; write clean, structured code, with easy-to-follow logic.
**The comparisons are not case-sensitive, both (a,e,i,o,u) and (A,E,I,O,U) count as vowels. Use a switch statement to compare each character in userStr to the vowels. Do not use if statements to check if the character is one of the vowels. Do not put the vowels on a list, array, or a string of vowels. Use a simple switch statement. Make the logic and code clean and readable. Avoid unnecessary processing and unnecessary variables. Use meaningful variable names. Use indentation. Use comments to explain your logic.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started