I have problem writing some method … so if some1 can help, i would really appreciate it. Thank you.
Task:
– read word
– turn it in “obenglobish” – that means that you must add “OB” before vowel …
for example: english will become –> OBenglOBish …
exception: two vowel in the row && -e is the last char in the word.
This is what i wrote, no matter on exceptions:
import acm.program.*;
public class ObenGlobishX extends ConsoleProgram {
public void run() {
println("OBENGLOBISH");
while (true) {
String word = readLine("Enter a word: ");
if (word.equals("")) break;
println(word + " --> " + obenglobish(word));
}
}
private String obenglobish (String word) {
String result = "";
for (int i = 0; i < word.length(); i++) {
char c = word.charAt(i);
if (isEnglishVowel(c)) result = result + "ob" + c;
else result += c;
}
return result;
}
private boolean isEnglishVowel(char x) {
if (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u') return true;
return false;
}
}
It works for word like English and Rot (robot), but for word gooiest it doesn’t work – two oo’s … need to find out how to modify method to get correct results … that means:
gooiest -> gobooiest
amaze -> obamobaze
etc.
THX
1 Answer