Rearrange Vowels and Consonants ISC 2019 Theory

A class Rearrange has been defined to modify a word by bringing all the vowels in the word at the beginning followed by the consonants.

Example: ORIGINAL becomes OIIARGNL

Some of the members of the class are given below:

Class name: Rearrange
Data members/instance variables:
word: to store a word.
newWord: to store the rearranged word.
Member functions/methods:
Rearrange(): default constructor.
void readWord(): to accept the word in uppercase.
void freqVowelCon(): finds the frequency of vowels and consonants in the word and displays them with an appropriate message.
void arrange(): rearranges the word by bringing the vowels at the beginning followed by consonants.
void display(): displays the original word along with the rearranged word.

Specify the class Rearrange, giving details of the constructor, void readWord(), void freqVowelCon(), void arrange() and void display(). Define the main() function to create an object and call the functions accordingly to enable the task.

import java.io.*;
class Rearrange{
    private String word;
    private String newWord;
    public Rearrange(){
        word = new String();
        newWord = new String();
    }
    public void readWord()throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.print("Enter the word: ");
        word = br.readLine();
    }
    public void freqVowelCon(){
        word = word.toUpperCase();
        int v = 0;
        int c = 0;
        for(int i = 0; i < word.length(); i++){
            char ch = word.charAt(i);
            if(Character.isLetter(ch)){
                switch(ch){
                    case 'A':
                    case 'E':
                    case 'I':
                    case 'O':
                    case 'U':
                    v++;
                    break;
                    default:
                    c++;
                }
            }
        }
        System.out.println("Frequency of vowels: " + v);
        System.out.println("Frequency of consonants: " + c);
    }
    public void arrange(){
        String v = new String();
        String c = new String();
        word = word.toUpperCase();
        for(int i = 0; i < word.length(); i++){
            char ch = word.charAt(i);
            if(Character.isLetter(ch)){
                switch(ch){
                    case 'A':
                    case 'E':
                    case 'I':
                    case 'O':
                    case 'U':
                    v += ch;
                    break;
                    default:
                    c += ch;
                }
            }
        }
        newWord = v + c;
    }
    public void display(){
        System.out.println("Original word: " + word);
        System.out.println("Rearranged word: " + newWord);
    }
    public static void main(String args[])throws IOException{
        Rearrange obj = new Rearrange();
        obj.readWord();
        obj.freqVowelCon();
        obj.arrange();
        obj.display();
    }
}

3 thoughts on “Rearrange Vowels and Consonants ISC 2019 Theory

  1. 2 programs are given which states that:
    WAP in JAVA to arrange the digits of a number in descending order.the number to be accepted by the user is positive
    Sample Input: 6729
    Sample Output:9762
    WAP in JAVA to store the numbers in a 4 X 4 matrix in Double Dimensional Array.Arrange the numbers of each row in ascending order using Selection Sort Technique and display the result
    Original matrix:
    22 14 23 25
    81 26 31 10
    58 64 17 12
    55 33 26 14
    Sorted matrix:
    14 22 23 25
    10 26 31 81
    12 17 58 64
    14 26 33 55

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.