Page 396 - Computer science 868 Class 12
P. 396
public void arrange() {
String v = new String();
String c = new String();
wrd = wrd.toUpperCase();
for(int i = 0; i < wrd. length(); i++) {
char ch = wrd.charAt(i);
if(Character.isLetter(ch)) {
switch(ch) {
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
v += ch;
break;
default:
c += ch;
}
}
}
newwrd = v + c;
}
public void display() {
System.out.println(“Original word:" + wrd);
System.out.println(“Rearranged word:" + newwrd);
}
public static void main(String args[])throws IOException {
Rearrange obj = new Rearrange();
obj.readword();
obj.freq_vow_con();
obj.arrange();
obj.display();
}
}
5. A class Capital has been defined to check whether a sentence has words beginning with a capital letter or not. Some of the
members of the class are given below: [ISC 2018]
Class name : Capital
Data Member/Instance variable
sent : to store a sentence
freq : stores the frequency of words beginning with a capital letter
Member Functions/Methods
Capital() : default constructor
void input() : to accept the sentence
boolean isCap(String w) : checks and returns true if word begins with a capital letter,
otherwise returns false
void display() : displays the sentence along with the frequency of the words
beginning with a capital letter
Specify the class Capital, giving the details of the constructor(), void input(), boolean isCap(String) and void display(). Define
the main() function to create an object and call the functions accordingly to enable the task.
394394 Touchpad Computer Science-XII

