Computer Science, asked by cutedevil81, 8 months ago


Design a class Word Wise 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:
Word Wise
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 Word Wise giving details of the constructor( ), void readsento,
int freq vowel(String) and void arrange(). Define the main() function to create an object
and call the functions accordingly to enable the task.​

Answers

Answered by 1minutememes1208
30

here's your answer :

import java.util.Scanner;

public class  WordWise

{

   String str;

   

   WordWise()

   {

       str="";

   }

   void readsent()

   {

       Scanner in = new Scanner(System.in);

       str=in.nextLine();

   }

   int freq_vowel(String w)

   {

       int c = 0;

       for(int i=0;i<w.length();i++)

       {

           

           char ch = w.charAt(i);

           char ch1 = Character.toUpperCase(ch);

           if(ch1=='A' || ch1=='E' || ch1=='I' || ch1=='O' || ch1=='U')

           {

               c++;

           }

       }

       return c;

   }

   void arrange()

   {

       WordWise obj = new WordWise();

       

       String s = str+" ";

       

       String word="";

       

       for(int i=0;i<s.length();i++)

       {

           if(s.charAt(i)==' ')

           {

               int Vcount = obj.freq_vowel(word);

               System.out.println(word + " " + Vcount);

               word="";

           }

           else

           {

               word=word+s.charAt(i);

           }

       }

   }

   public static void main(String args[])

   {

       WordWise obj = new WordWise();

       

       obj.readsent();

       obj.arrange();

   }

}

   

Similar questions