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 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 letters, int begin) { String concat; if (letters.size() == begin) { concat = ""; } else { concat = letters.get(begin) + Test5B.concat(letters, begin + 1); } return concat; } }