Design a class WordWise to separate words from a sentence and
find the frequency of the vowels in each word.
Some of the members of the class are given below:
Class name : WordWise
Data members/instance variables:
str : to store a sentence
Member functions/methods:
WordWise( ) : default constructor
void readsent( ) : to accept a sentence
int freq_vowel(String w) : returns the frequency of
vowels in the parameterized
string w
void arrange( ) : displays each word of the
sentence in a separate line
along with the frequency of
vowels for each word by
invoking the function
freq_vowel( )
Define the class WordWise giving details of the
constructor( ), void readsent(), int freq_vowel(String) and
void arrange(). Define the main( ) function to create an
object and call the functions accordingly to enable the
task.
import java.util.*;
class WordWise
{
String str;
WordWise()
{
str="";
}
void readsent()
{
Scanner sc= new Scanner(System.in)
str=sc.nextLine();
}
int freq_vowel(String w)
{
int i=0, c=0;
for(i=0; i<w.length(); i++)
if("AEIOUaeiou".indexOf(w.charAt(i))>=0)
c++;
return c;
}
void arrange()
{
int i=0, c=0, j=0; char ch=' '; String Res="";
for(i=0; i<str.length(); i++)
{
ch=str.charAt(i);
if(ch!=' ')
Res=Res+ch;
else
{
c=freq_vowel(Res);
System.out.println(Res+"\tFREQUENCY OF VOWELS IS-"+c+"\n");
Res="";
}
}
}
void main()
{
WordWise obj= new WordWise();
obj.readsent();
obj.arrange();
}
}