0% found this document useful (0 votes)
8 views2 pages

String Programs

The document outlines the design of a Java class named WordWise that processes a sentence to separate words and calculate the frequency of vowels in each word. It includes a default constructor, methods to read a sentence, count vowels, and display each word with its vowel frequency. A main function is also defined to create an instance of the class and execute the methods for the desired functionality.

Uploaded by

smartboyop123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

String Programs

The document outlines the design of a Java class named WordWise that processes a sentence to separate words and calculate the frequency of vowels in each word. It includes a default constructor, methods to read a sentence, count vowels, and display each word with its vowel frequency. A main function is also defined to create an instance of the class and execute the methods for the desired functionality.

Uploaded by

smartboyop123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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();
}
}

You might also like