Related questions
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 nowThis is a popular solution!
Step by stepSolved in 2 steps with 2 images
- The method lower() returns a string with all the characters converted to lowercase. True or Falsearrow_forwardWrite a method which will remove any given character from a String?arrow_forwardFor each item, write a single regular expression that matches that item. Note that in ALL cases, the entire string must match without additional characters. 1. A string of digits that contains only digits and contains exactly two fives. Examples of acceptable strings include: "15445", "55", "05563" o The string should be rejected if it contains anything other than a digits. 2. A regular expression that matches a time expressed in the form "1:45 PM". o The hours part must be a number from 1 to 12, the minutes range from 00 to 59, and the time must indicate either AM or PM (uppercase only and preceded by exactly one space). 3. A regular expression that matches a string representing a comma separated list of variable names such as: hello, get_max, sum3 o A variable name consists of letters, digits, and underscores but cannot start with a digit. o There is exactly one space after every comma. No other spaces are allowed. o Commas and spaces are not allowed before the first name and after...arrow_forward
- Write a program that converts date formats from American Format: "February 4, 2021" to International Format, such as "2021-February-4". Hint: you may use several string methods, including: str.indexOf(c) and str.substring(p, q). Note: java programming, must detect commaarrow_forwarde) Create a new StringBuilder from the String "Prepare for your Midterm Exam". Check the capacity of the StringBuilder and if it's empty. Find the index of the letter 'y'. Delete a substring from the starting index till this index (of 'y'). Insert a string "Good luck on " at the beginning of the StringBuilder. Append '!" to it. Print your StringBuilder to Console.arrow_forwardThe loop below is intended to collect all characters that occur more than once in a given string. When you try it out with a string such as "Mississippi", you will note that that letters that occur three or more times are collected more than once. Modify the loop so that each repeated letter is collected exactly once. For example, when s is "Mississippi", result should be "si" and not "sissii" Only allowed to edit code in the /* Your code goes here */ portion. Thanks for the help!arrow_forward
- Create a single regular expression that matches a string of digits and contains exactly two fives. Examples of acceptable strings include: "15445 " , " 55 " , " 05563 " . However, the string is to be rejected if it contains anything other than digits.arrow_forwardFor each item, write a single regular expression that matches that item. Note that in ALL cases, the entire string must match without additional characters. A string of digits that contains only digits and contains exactly two fives. Examples of acceptable strings include: "15445", "55", "05563" The string should be rejected if it contains anything other than a digits. 2. A regular expression that matches a time expressed in the form "1:45 PM". The hours part must be a number from 1 to 12, the minutes range from 00 to 59, and the time must indicate either AM or PM (uppercase only and preceded by exactly one space). 3. A regular expression that matches a string representing a comma separated list of variable names such as: hello, get_max, sum3 A variable name consists of letters, digits, and underscores but cannot start with a digit. There is exactly one space after every comma. No other spaces are allowed. Commas and spaces are not allowed before the first name...arrow_forwardWhen the target string includes a digit, what occurs in the Str ucase method from Section 9.3?arrow_forward
- Text book imageComputer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONText book imageComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceText book imageNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Text book imageConcepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningText book imagePrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationText book imageSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY