Python,C,C++ and JAVA programs for CBSE, ISC, B.Tech and I.T Computer Science and MCA students

The Programming Project: ISC COMPUTER SCIENCE THEORY PAPER JAVA PROGRAMS - 2019 Question 9

Monday, January 18, 2021

ISC COMPUTER SCIENCE THEORY PAPER JAVA PROGRAMS - 2019 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 ISC2019Q9 {
       public static void main(String[] args) {
       Rearrange obj = new Rearrange();
       obj.readWord();
       obj.vowelCount();
       obj.rearrangeWord();
       obj.display();
     }
}
class Rearrange {
    public void display() {
        System.out.println("ORIGINAL WORD:"+word);
        System.out.println("REARRANGED WORD:"+word_final);
    }
    public void rearrangeWord() {
        String vowels_beg ="";
        String conso_end ="";
        boolean flag;
        for (int i = 0;i<word.length();i++) {
            flag = false;
            for (int j =0;j<5;j++)
                if(word.charAt(i) == vowels[j]) {
                    flag = true;
                    break;
                }
            if (flag == true)
                vowels_beg += word.charAt(i);
            else
                conso_end +=word.charAt(i);
        }
        word_final = vowels_beg+conso_end;
    }
    public void vowelCount() {
        for (int i = 0;i<word.length();i++) {
            for (int j =0;j<5;j++)
                if(word.charAt(i) == vowels[j])
                    frequency_vowel_count++;
        }
        System.out.println("Number of vowels isn the word "+word+" is:"+frequency_vowel_count);
    }
    public void readWord() {
        Scanner input = new Scanner(System.in);
        boolean flag = true;
        do {
            System.out.println("Enter the word in upper case:");
            word = input.next();
            for(int i = 0;i<word.length();i++) {
                flag = Character.isUpperCase(word.charAt(i));
                if (flag == false ) {
                    System.out.println("You have not entered the word in upper case, try again:");
                    break;
                }
            }
        } while(flag == false);
        input.close();
    }
    Rearrange(){
        this.word = "";
        this.word_final ="";
        this.frequency_vowel_count = 0;
    }
    static char[] vowels = new char[] {'A','E','I','O','U'}; 
    private String word;
    private String word_final;
    private int frequency_vowel_count;
}

No comments:

Post a Comment