Implement the Test5B class. A skeleton can be found here. The API can be found here.
package test5;
import java.util.List;
public class Test5B
{
/**
* Returns the conversion of the given string by replacing each
* 0 (zero) with O (capital o) and each 1 with I.
*
* @param binary a string of 0s and 1s
* @pre. binary only consists of 0s and 1s
* @return the conversion of the given string by replacing each
* 0 (zero) with O (capital o) and each 1 with I.
*/
public static String convert(String binary)
{
String convert;
if (binary.length() == 0)
{
convert = "";
}
else
{
convert = (binary.charAt(0) == '0' ? "O" : "I") + Test5B.convert(binary.substring(1));
}
return convert;
}
/**
* Returns the string consisting of the characters of the given list.
*
* @param letters a list of characters
* @pre. letters != null
* @return the string consisting of the characters of the given list.
*/
public static String concat(List<Character> letters)
{
return Test5B.concat(letters, 0);
}
/**
* Returns the string consisting of the characters of the sub list
* of the given list, beginning at the given index.
*
* @param letters a list of characters
* @pre. list != null
* @param begin the begin index of the sub list
* @pre. begin >= 0 && begin <= list.size()
* @return the string consisting of the characters of the sub list
* of the given list, beginning at the given index.
*/
public static String concat(List<Character> letters, int begin)
{
String concat;
if (letters.size() == begin)
{
concat = "";
}
else
{
concat = letters.get(begin) + Test5B.concat(letters, begin + 1);
}
return concat;
}
}
/**
* Returns 6n + 6, where n is the given integer.
*
* @param n an integer.
* @pre. 0 <= n && n <= 100.
* @return 6n + 6.
*/
public static int recursive(int n)
{
if (n == 100)
{
return 606;
}
else if (n == 99)
{
return 600;
}
else
{
return recursive(n + 2) - 12;
}
}