String Warp

Implementing unusual string operations.

Overview

In this assignment, you’ll implement and test a method that extracts a substring of a specified string, and (optionally) reverses it.

Implementation

Declaration

In the edu.cnm.deepdive.StringWarp class, the substring method is declared with the following signature, return type, and modifiers:

public static String substring(String input, int beginIndex, int endIndex) throws IndexOutOfBoundsException

The implementation must not change the modifiers, return type, method name, parameter types/number/order, or possible exceptions shown above. For more method declaration details, see the Javadoc documentation.

Specifications

For example, the code fragment

StringWarp.substring("Kotlin", 1, 5)

must return

"otli"

However,

StringWarp.substring("Kotlin", 5, 1);

must return

"ilto"

Note that the second output string is the same is the first, but reversed.

Tips

Unit tests

The StringWarp.substring implementation will be verified using these test cases:

input beginIndex endIndex Expected return value Expected exception
"bootcamp" 2 6 "otca" N/A
"bootcamp" 6 2 "acto" N/A
"bootcamp" 3 3 "" N/A
"algorithm" 0 9 "algorithm" N/A
"algorithm" 9 0 "mhtirogla" N/A
"bootcamp" -1 0 N/A StringIndexOutOfBoundsException
"bootcamp" 0 -1 N/A StringIndexOutOfBoundsException
"bootcamp" 0 9 N/A StringIndexOutOfBoundsException
"bootcamp" 9 0 N/A StringIndexOutOfBoundsException