Question: JAVA: Write a class with a constructor that accepts a String object as its argument. The class should have a method that returns the number

JAVA:

Write a class with a constructor that accepts a String object as its argument. The class should have a method that returns the number of vowels in the string, and another method that returns the number of consonants in the string. (Spaces count as neither vowels nor consonants and should be ignored.) Demonstrate the class in a program that performs the following steps: 1. The user is asked to enter a string. 2. The program displays the following menu: 1. Count the number of vowels in the string 2. Count the number of consonants in the string 3. Count both the vowels and consonants in the string 4. Enter another string 5. Exit the program The user can select options by inputting the appropriate number. If option 1, 2, or 3 is selected, the result should be printed to the screen. When displaying the number of vowels, do it in the format: Vowels: 3 When displaying consonants, do it in the format: Consonants: 5 When displaying both, do it in the format: Vowels: 3 Consonants: 5 3. The program performs the operation selected by the user and repeats until the user selects 5 to exit the program.

OUTPUT like:

Enterastring:Supercalifragilisticexpialidocious

Enteranumber

1.Countthenumberofvowelsinthestring

2.Countthenumberofconsonantsinthestring

3.Countboththevowelsandconsonantsinthestring

4.Enteranotherstring

5.Exittheprogram:1

Vowels:16

Enteranumber

1.Countthenumberofvowelsinthestring

2.Countthenumberofconsonantsinthestring

3.Countboththevowelsandconsonantsinthestring

4.Enteranotherstring 5.Exittheprogram:2

Consonants:18

Enteranumber

1.Countthenumberofvowelsinthestring

2.Countthenumberofconsonantsinthestring

3.Countboththevowelsandconsonantsinthestring

4.Enteranotherstring

5.Exittheprogram:4

Enterastring:Aspoonfulofsugarmakesthemedicinegodown

Enteranumber

1.Countthenumberofvowelsinthestring

2.Countthenumberofconsonantsinthestring

3.Countboththevowelsandconsonantsinthestring

4.Enteranotherstring

5.Exittheprogram:3

Vowels:16

Consonants:22

Enteranumber

1.Countthenumberofvowelsinthestring

2.Countthenumberofconsonantsinthestring

3.Countboththevowelsandconsonantsinthestring

4.Enteranotherstring

5.Exittheprogram:5

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!