Frequency of Words and Vowels

A sentence is terminated either by “.”, “!” or “?” followed by a space. Input a piece of text consisting of sentences. Assume that there will be a maximum of 10 sentences in block letters.

Write a program to:

  1. Obtain the length of the sentence (measured in words) and the frequency of vowels in each sentence.
  2. Generate the output as shown below using the given data.

Sample data:

INPUT:
Hello! How are you? Hope everything is fine. Best of luck.
OUTPUT:

Sentence        Number of Vowels        Number of Words
1 2 1
2 5 3
3 8 4
4 3 3
Sentence    Number of Vowels/Words
1 VVVVVV
WWW
2 VVVVVVVVVVVVVVV
WWWWWWWWW
3 VVVVVVVVVVVVVVVVVVVVVVVV
WWWWWWWWWWWW
4 VVVVVVVVV
WWWWWWWWW

Scale used is 1:3.

Program:

import java.io.*;
import java.util.StringTokenizer;
class Frequency{
    public static void main(String args[])
    throws IOException{
        InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(in);
        System.out.println("Enter text:");
        String text = br.readLine();
        text = text.toUpperCase();
        StringTokenizer st1 = new StringTokenizer(text, ".?!");
        int count = st1.countTokens();
        if(count > 10){
            System.out.println("Maximum 10 sentences allowed.");
            return;
        }
        String s[] = new String[count];
        int fw[] = new int[count];
        int fv[] = new int[count];
        for(int i = 0; i < s.length; i++)
            s[i] = st1.nextToken();
        for(int i = 0; i < s.length; i++){
            StringTokenizer st2 = new StringTokenizer(s[i], " ");
            fw[i] = st2.countTokens();
            for(int j = 0; j < s[i].length(); j++){
                char ch = s[i].charAt(j);
                switch(ch){
                    case 'A':
                    case 'E':
                    case 'I':
                    case 'O':
                    case 'U':
                    fv[i]++;
                }
            }
        }
        System.out.println("\nSentence\tNo. of Vowels\tNo. of Words");
        for(int i = 0; i < s.length; i++)
            System.out.println((i + 1) + "\t\t" + fv[i] + "\t\t" + fw[i]);
        System.out.println("\nSentence\tNo. of Vowels/Words");
        for(int i = 0; i < s.length; i++){
            System.out.print((i + 1) + "\t\t");
            for(int j = 0; j < fv[i]; j++)
                System.out.print("VVV");
            System.out.println();
            System.out.print("\t\t");
            for(int j = 0; j < fw[i]; j++)
                System.out.print("WWW");
            System.out.println();
        }
    }
}