There is one programming question and five other questions.
Instructions for submitting your programming question solution are given in the Programming question section. You may submit as many times as you want; your most recent submission will be the one recorded.
Instructions for submitting your answers to the short answer questions are given in the Short Answer Questions section. You may submit as many times as you want; your most recent submission will be the one recorded.
Implement the Test5F class and provide the Javadoc comments needed to reproduce the API for the two required methods. You may omit the part of the comments that describe the examples (i.e., document the parameters, the return value (if any), and the method description excluding the examples).
Submit your program using the following command in a terminal (make sure you are in the directory containing your file Test5F.java):
submit 2030 test5F Test5F.java
package eecs2030.test5; import java.util.List; public class Test5F { /** * Returns a string where the case of each letter is flipped compared to the * corresponding letter in s. For example, if s is the string "abcDEF" then * flipCase(s) returns "ABCdef". The empty string is returned if s is equal * to the empty string. * * @param s * a non-null string consisting of English letter characters * @return a string where the case of each letter is flipped compared to the * corresponding letter in s */ public static String flipCase(String s) { if (s.length() == 0) { return ""; } char c = s.charAt(0); if (Character.isLowerCase(c)) { return Character.toUpperCase(c) + Test5F.flipCase(s.substring(1)); } return Character.toLowerCase(c) + Test5F.flipCase(s.substring(1)); } /** * Removes all duplicated strings from a non-null and sorted list of strings * maintaining the sorted order of the strings. If the list contains unique * strings then the list remains unchanged. For example, if t is the list * ["a", "b", "c", "d"] then unique(t) would do nothing. If t is the list * ["w", "w", "w", "x", "y", "y", "z"] then unique(t) would modify t so that * it became the list ["w", "x", "y", "z"]. * * @param t * a non-null and sorted list of strings that the method modifies * so that it contains no duplicated strings (and the list remains in * sorted order). */ public static void unique(List<String> t) { if (t.size() < 2) { return; } String first = t.get(0); String second = t.get(1); if (first.equals(second)) { t.remove(0); Test5F.unique(t); } Test5F.unique(t.subList(1, t.size())); } }
/** * Returns the string made up of the characters in s starting * from index idx and going to the end of s. For * example, * * endOf("abcdef", 0) returns "abcdef" * endOf("abcdef", 1) returns "bcdef" * endOf("abcdef", 2) returns "cdef" * endOf("abcdef", 3) returns "def" * * An empty string is returned if idx is greater than or equal to * the length of s. * * @param s * a string * @param idx * the starting index in s * @pre. idx >= 0 * @return the string made up of the characters in s starting from index idx * and going to the end of s */ public static String endOf(String s, int idx) { String result = ""; if (idx >= s.length()) { result = ""; } else { result = s.charAt(idx) + endOf(s, idx + 1); } return result; }