Rearrange Vowels ISC Computer Science 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 consonants.

Example: ORIGINAL becomes OIIARGNL

Some of the members of the class are given below:

Class name: Rearrange

Data members/instance variables:
wrd: to store a word
newwrd: to store the rearranged word

Member functions/methods:
Rearrange(): default constructor
void readWord(): to accept the word in uppercase
void frequency(): 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 frequency(), void arrange() and void display(). Define the main() function to create an object and call the functions accordingly to enable the task.

import java.util.Scanner;
class Rearrange{
    String wrd;
    String newwrd;
    public Rearrange(){
        wrd = new String();
        newwrd = new String();
    }
    public void readWord(){
        Scanner in = new Scanner(System.in);
        System.out.print("Enter the word: ");
        wrd = in.nextLine().toUpperCase();
    }
    public void frequency(){
        int f = 0;
        for(int i = 0; i < wrd.length(); i++){
            char ch = wrd.charAt(i);
            if("AEIOU".indexOf(ch) >= 0)
                f++;
        }
        System.out.println("Frequency of vowels: " + f);
    }
    public void arrange(){
        String c = "";
        for(int i = 0; i < wrd.length(); i++){
            char ch = wrd.charAt(i);
            if("AEIOU".indexOf(ch) >= 0)
                newwrd += ch;
            else
                c += ch;
        }
        newwrd += c;
    }
    public void display(){
        System.out.println("Original word: " + wrd);
        System.out.println("Rearranged word: " + newwrd);
    }
    public static void main(String args[]){
        Rearrange obj = new Rearrange();
        obj.readWord();
        obj.frequency();
        obj.arrange();
        obj.display();
    }
}

Comments

Popular posts from this blog

Encrypt Program ISC Specimen 2023 Theory

No Repeat Program ISC Computer Science 2022 Semester 2 Theory

Bank Inheritance Program ISC Specimen 2023 Theory