Question 9

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 member/instance variable:
wrd to store a word
newwrd to store the rearranged word
Member functions/methods:
Rearrange( ) default constructor
void readword( ) to accept the word in UPPER case
void freq_vow_con( ) 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 the details of the constructor( ), void readword( ), void freq_vow_con( ), 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.*; 
public class Rearrange 
{ 
    String wrd,newwrd; 
    static Scanner x=new Scanner(System.in); 
    Rearrange(){} 
    void readword() 
    { 
        System.out.println("Enter a word" ); 
        wrd=x.next(); 
        wrd=wrd.toUpperCase(); 
    } 
    void freq_vow_con() 
    { 
        int s=0,s1=0; 
        char ch; 
        for(int i=0;i<wrd.length();i++) { 
            ch=wrd.charAt(i); 
            if("AEIOU".indexOf(ch)!=-1) 
                s++; 
            }
            s1= wrd.length()-s; 
            System.out.println("vowels = "+ s); 
            System.out.println("consonants = " + s1); 
        } 
        void arrange() 
        { 
            char ch; 
            String p="",q=""; 
            for(int i=0;i<wrd.length();i++) { 
                ch=wrd.charAt(i); 
                if("AEIOU".indexOf(ch)!=-1) 
                    p +=ch; 
                else 
                    q +=ch; 
                }
            newwrd= p+q; 
        }
        void display() 
        { 
            System.out.println("Original word = "+ wrd); 
            System.out.println("Rearranged word = "+ newwrd); 
        } 
        static void main() 
        { 
            Rearrange obj=new Rearrange(); 
            obj.readword(); 
            obj.freq_vow_con(); 
            obj.arrange(); 
            obj.display(); 
        } 
}
This entry was posted in ISC2019. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *