Question
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
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.
SAMPLE RUN #1: java Driver
Interactive Session Standard Input Standard Error (empty) Standard Output Hide Invisibles
Highlight: NoneStandard Input OnlyPrompts OnlyStandard Output w/o PromptsFull Standard OutputAllShow Highlighted Only
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
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