JUnit: P2J3Test.java One last batch of transitional problems adapted from the instructor's collection of Python graded labs. Only three methods to write this time, though. The JUnit test for these labs uses the warandpeace.txt text file as source of data, so please ensure

Programming with Microsoft Visual Basic 2017
8th Edition
ISBN:9781337102124
Author:Diane Zak
Publisher:Diane Zak
Chapter10: Classes And Objects
Section: Chapter Questions
Problem 2E: Open the Palace Solution.sln file contained in the VB2017\Chap10\Palace Solution folder. Use Windows...
icon
Related questions
Question

Reverse The Verse
JUnit: P2J3Test.java
One last batch of transitional problems adapted from the instructor's collection of Python graded
labs. Only three methods to write this time, though. The JUnit test for these labs uses the
warandpeace.txt text file as source of data, so please ensure that this text file has been properly
copied into your course labs project folder. This text file, same as any other data files you would
use, does not show up anywhere in the BlueJ project screen, even though it is part of the
project directory that contains the Java source code for the solutions and the unit tests.
public static void reverseAscendingSubarrays(int[] items)
Rearrange the elements of the given array of integers in place (that is, do not create and return a
new array) so that the elements of every maximal strictly ascending subarray are reversed. For
example, given the array {5, 7, 10, 4, 2, 7, 8, 1, 3} (the pretty colours indicate the
ascending subarrays and are not actually part of the argument), after executing this method, the
elements of the array would be {10, 7, 5, 4, 8, 7, 2, 3, 1}. Given another argument
array {5, 4, 3, 2, 1}, the contents of that array would stay as {5, 4, 3, 2, 1} seeing
that its each element is a maximal ascending subarray of length one.
public static String pancakeScramble(String text)
This nifty little problem is taken from the excellent Wolfram Challenges problem site where you can
also see examples of what the result should be for various arguments. Given a text string,
construct a new string by reversing its first two characters, then reversing the first three characters
of that, and so on, until the last round where you reverse your entire current string.
This problem is an exercise in Java string manipulation. For some mysterious reason, the Java
String type does not come with a reverse method. The canonical way to reverse a Java string
str is to first convert it to mutable StringBuilder, reverse its contents, and convert the result
back to an immutable string, that is,
str = new StringBuilder(str).reverse().toString();
A bit convoluted, but does what is needed without fuss or muss. Maybe one day the Java strings will
come with the reverse method built in, just like the string data types of all sensible programming
languages. Or at least have that available as a utility somewhere in the standard library.
public static String reverseVowels(String text)
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.

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning