C Programs Tutorials | IT Developer
IT Developer

Java Programs - Solved 2016 Theory Paper ISC Computer Science



Share with a Friend

Solved 2016 Theory Paper ISC Computer Science

Class 12 - ISC Computer Science Solved Theory Papers

ConsChange Program - ISC 2016 Theory

A class ConsChange has been defined with the following details:

Class name: ConsChange
Data members/instance variables:
word: stores the word.
len: stores the length of the word.

Member functions/methods:
ConsChange(): default constructor
void readWord(): accepts the word in lowercase.
void shiftCons(): shifts all the consonants of the word at the beginning followed by the vowels (e.g. spoon becomes spnoo).
void changeWord(): changes the case of all occurring consonants of the shifted word to uppercase, for e.g. spnoo becomes SPNoo)
void display(): displays the original word, shifted word and the changed word.

Specify the class ConsChange giving the details of the constructor, void readWord(), void shiftCons(), void changeWord() and void show(). Define the main() function to create an object and call the functions accordingly to enable the task.

import java.io.*; class ConsChange{ private String word; private int len; public ConsChange(){ word = new String(); len = 0; } public void readWord()throws IOException{ InputStreamReader in = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(in); System.out.print("Word: "); word = br.readLine().toLowerCase(); word = word.trim(); if(word.indexOf(' ') > 0) word = word.substring(0, word.indexOf(' ')); len = word.length(); } public void shiftCons(){ String c = new String(); String v = new String(); for(int i = 0; i < len; i++){ char ch = word.charAt(i); switch(ch){ case 'a': case 'e': case 'i': case 'o': case 'u': v += ch; break; default: c += ch; } } word = c + v; System.out.println("Shifted word: " + word); } public void changeWord(){ int pos = 0; loop: for(int i = 0; i < len; i++){ char ch = word.charAt(i); switch(ch){ case 'a': case 'e': case 'i': case 'o': case 'u': pos = i; break loop; } } String c = word.substring(0, pos); c = c.toUpperCase(); String v = word.substring(pos); word = c + v; System.out.println("Changed word: " + word); } public void show(){ System.out.println("Original word: " + word); this.shiftCons(); this.changeWord(); } public static void main(String args[]) throws IOException{ ConsChange obj = new ConsChange(); obj.readWord(); obj.show(); } }

Output

 
OUTPUT 1:

Word: ITDeveloper
Original word: itdeveloper
Shifted word: tdvlprieeoe
Changed word: TDVLPRieeoe

OUTPUT 2: 

Word: University
Original word: university
Shifted word: nvrstyuiei
Changed word: NVRSTYuiei