Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

*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.

*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.

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

More Books

Students also viewed these Databases questions

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago