Fields 0.5 / 1 -is there a field public static final String TEST_VERSION equal to "C"? Constructors 1 / 1 -is there a private constructor? Methods -join 1 / 1 -are the strings concatenated somehow? 2 / 2 -is the correct value returned? -shortest 1 / 1 -correctly throws the expected exception? 2 / 2 -returns the correct value when s is shorter than t? 2 / 2 -returns the correct value when t is shorter than s? -distance 1 / 1 -is there a loop over the characters of the strings? 1 / 1 -in the loop body, are corresponding characters compared correctly? 1 / 1 -in the loop body, is a counter incremented for matching characters? 1 / 1 -is the correct result returned? -mostFrequent 4 / 4 -is the correct value returned? -------------------- TA Comments: -a utility class should have a private constructor -TEST_VERSION should be public -your code is written very clearly -------------------- Unit tester output: YOUR SUMBISSION FAILED SOME UNIT TESTS Here is the test output: java -classpath .:/home/burton/work/teaching/2017F/2030/marking/secEtest1C/_jar/* org.junit.runner.JUnitCore test1.Test1Suite JUnit version 4.12 .E.E.......... Time: 0.123 There were 2 failures: 1) test00(test1.StringUtilTest) java.lang.AssertionError: found a non-private constructor 2) test01_field(test1.StringUtilTest) java.lang.AssertionError: field TEST_VERSION is not public or not final or not static FAILURES!!! Tests run: 12, Failures: 2 -------------------- Your submission: package test1; import java.util.*; /** * A utility class for working with strings. * */ public class StringUtil { private static final String TEST_VERSION = "C"; public static String join(String s, String t, String sep) { return s + sep + t; } public static String shortest(String s, String t) { if (s.length() == t.length()) { throw new IllegalArgumentException(); } if (s.length() < t.length()) { return s; } return t; } public static int distance(String s, String t) { int dist = s.length(); for (int i = 0; i < s.length(); i++) { if (s.charAt(i) == t.charAt(i)) { dist -=1; } } return dist; } public static char mostFrequentChar(String s) { List<Character> chars = new ArrayList<>(); Set<Character> unique = new HashSet<>(); for (char letter : s.toCharArray()) { unique.add(letter); chars.add(letter); } int max = 0; char frequent = s.charAt(0); for (char letter: unique) { int freq = Collections.frequency(chars, letter); if (freq > max) { max = freq; frequent = letter; } } return frequent; } } -------------------- Written answers marking scheme A 1 / 2 is a suitable definition given? B 2 / 3 are the values for a, b, and c correct? C 1 / 1 documentation for the parameter s is missing? 1 / 1 documentation for the return value is missing? 1 / 1 there is no precondition for the method shortest? D 2 / 2 is there a correct test case and suitable explanation? 2 / 2 is suitable explanation given for why the test case should not be used? -------------------- TA Comments A. It absolutely means that that the value cannot be changed. You can declare a field only once regardless if the field is final or not. A final field can be assigned a value only once. B. c = 400a (the address of second, the shortest string) -------------------- Your submission: A. Final means that the variable can only be declared once and not again. This does not mean that it can not be changed B. a = 300a b = 400a c = 800a C. 1) Only the parameter t is shown in the JavaDoc, while the method requires 2. 2) The precondition is not correct, because the API checks for the lengths of the strings being the same and throws an exception for it. A precondition would mean that the API would account for a specific situation. 3) There is no section to describe what it returned by the method. D. a) Yes, if the strings were to be of length 0, the API would return -1, but the Javadoc states that it should return 0. The case would be: assertEquals(0, StringUtil.distance("", "")); b) No, because the API states that a precondition for this method is that the 2 strings have the same length. This mean that the API does not guarantee any sort of meaningful result in that situation. --------------------