Create a class with a single constructor that accepts a String object as its arg
ID: 3623976 • Letter: C
Question
Create a class with a single constructor that accepts a String object as its argument (parameter). The class must then have methods that:
1. Returns the number of vowels (a, e, i, o, u) in the string.
2. Returns the number of consonants in the string.
3. Returns the number of characters (both consonants and vowels) in the string.
4. Reverses the characters in the string for display.
Demonstrate your class with a program that performs the following steps:
1. The user is asked to enter a string.
2. The program displays the following menu:
****************************************************** * String Manipulation * ******************************************************
a. Count the number of vowels in the string
b. Count the number of consonants in the string
c. Count all characters in the string
d. Display the reversed the string
e. Enter another string
f. Exit the program
Please make a selection: _
3. The program performs the user selected operation, displays the results, then redisplays the menu, and repeats until the user selects f, to exit the program.
Your demonstration program must use the acm ConsoleProgram or use a Java program with a main method, your choice.
Explanation / Answer
import java.io.*; public class StringInfo{ private String str; //constructor with argument public StringInfo(String str){ this.str=str; } //no arg constructor public StringInfo(){ } //counts number of vowels public int countVowel(String str){ int count=0; for(int i=0;iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.