Given a text string, create and return a new string of same length where all vowels have been reversed, and all other characters are kept as they were. For simplicity, in this problem only the characters aeiouAEIOU are considered vowels, and y is never a vowel. For example, given the text string "Uncle Sente lives in Russia", this method should create and return the string "Ancli Sunti levis en Resseu". Furthermore, to make this problem more interesting and the result look more palatable, this method must maintain the capitalization of vowels based on the vowel character that was originally in the position that each new vowel character is moved into. For example, "Ilkka Markus" should become "Ulkka Markis" instead of "ulkka MarkIs". Use the handy character classification methods in the Character utility class to determine whether some particular character is in upper or lower case, and convert some character to its upper or lower case version as needed.
Given a text string, create and return a new string of same length where all vowels have been
reversed, and all other characters are kept as they were. For simplicity, in this problem only the
characters aeiouAEIOU are considered vowels, and y is never a vowel. For example, given the text string "Uncle Sente lives in Russia", this method should create and return the string
"Ancli Sunti levis en Resseu".
Furthermore, to make this problem more interesting and the result look more palatable, this
method must maintain the capitalization of vowels based on the vowel character that was
originally in the position that each new vowel character is moved into. For example, "Ilkka
Markus" should become "Ulkka Markis" instead of "ulkka MarkIs". Use the handy
character classification methods in the Character utility class to determine whether some
particular character is in upper or lower case, and convert some character to its upper or lower case
version as needed.
Here's the tester it must pass:
@Test public void testReverseVowels() throws IOException {
// Explicit test cases
assertEquals("", P2J3.reverseVowels(""));
assertEquals("X", P2J3.reverseVowels("X"));
assertEquals("Au", P2J3.reverseVowels("Ua"));
assertEquals("cDfghklM", P2J3.reverseVowels("cDfghklM"));
assertEquals("LOL", P2J3.reverseVowels("LOL"));
assertEquals("Jova, Pythan, C", P2J3.reverseVowels("Java, Python, C"));
assertEquals("Wuuleemoolaa", P2J3.reverseVowels("Waaloomeeluu"));
assertEquals("Ent, uat, boa, oka", P2J3.reverseVowels("Ant, oat, boa, uke"));
assertEquals("Stix nix hix pix", P2J3.reverseVowels("Stix nix hix pix"));
assertEquals("UoIeAxxxuOiEa", P2J3.reverseVowels("AeIoUxxxaEiOu"));
assertEquals("Lettor Y as not i vewel", P2J3.reverseVowels("Letter Y is not a vowel"));
// Testing with War and Peace
CRC32 check = new CRC32();
BufferedReader fr = new BufferedReader(
new InputStreamReader(new FileInputStream("warandpeace.txt"), "UTF-8")
);
String line = fr.readLine();
while(line != null) {
String result = P2J3.reverseVowels(line);
check.update(result.getBytes());
line = fr.readLine();
}
fr.close();
assertEquals(3844894811L, check.getValue());
}

Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images









