Fields
0.5 / 1  -is there a field public static final String TEST_VERSION equal to "C"?
 
Constructors
0 / 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?
0 / 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 equal to "C" as per the API specification 

-in distance, you can't use an enhanced for loop because you need 
to loop over both s and t at the same time; you have to use a regular 
loop and use the loop variable as an index 

--------------------
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....E.E.E....
Time: 0.11
There were 5 failures:

1) test00(test1.StringUtilTest)
java.lang.AssertionError: found a non-private constructor

2) test01_field(test1.StringUtilTest)
org.junit.ComparisonFailure: field TEST_VERSION has the wrong value expected:<[]C> but was:<[Test1]C>

3) test05_distance(test1.StringUtilTest)
java.lang.ArrayIndexOutOfBoundsException: 97

4) test06_distance(test1.StringUtilTest)
java.lang.ArrayIndexOutOfBoundsException: 101

5) test07_distance(test1.StringUtilTest)
java.lang.ArrayIndexOutOfBoundsException: 116

FAILURES!!!
Tests run: 12,  Failures: 5

--------------------

Your submission:

package test1;

import java.nio.charset.Charset;
import java.util.*;

/**
 * A utility class for working with strings.
 *
 */
public class StringUtil {
        
        public static final String TEST_VERSION = "Test1C";
        
        
        public static String join(String s, String t, String sep) {
                String result = "";
                result += s;
                result += sep;
                result += t;
                return result;
        }
        
        
        public static String shortest(String s, String t) throws IllegalArgumentException{
                if (s.length() == t.length()){
                        throw new IllegalArgumentException("Strings must not be of equal length!");
                }  else if (s.length() > t.length()) {
                        return t;
                } else {
                        return s;
                }
        }
        
        
        
        public static int distance(String s, String t) {
                char[] sChar = s.toCharArray();
                char[] tChar = t.toCharArray();
                int distance = 0;
                for (char i : sChar){
                        if(sChar[i] != tChar[i]){
                                distance++;
                        }
                }
                return distance;
        }
        
    
    public static char mostFrequentChar(String s) {
        Collection<Character> sCollection = new ArrayList<Character>();
        for (int i=0; i < s.length(); i++){
                char current = s.charAt(i);
                sCollection.add(current);
        }
        int frequencyHigh = 0;
        char highChar = 'a';
        for(char i : sCollection){
                int workingFrequency = Collections.frequency(sCollection, i);
                if (workingFrequency > frequencyHigh){
                        highChar = i;
                        frequencyHigh = workingFrequency;
                }
        }
        return highChar;
    }
}

--------------------

Written answers marking scheme

A 
1 / 2  is a suitable definition given?

B
0 / 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 
1 / 2  is there a correct test case and suitable explanation?
0 / 2  is suitable explanation given for why the test case should not be used?

--------------------
TA Comments

A. It absolutely means that the value can't be changed later; how can 
you change its value if you can only assign its value once?

B. 
    a = 300a   (the address of first which can be found in s)
    b = 400a   (the address of second which can be found in t)
    c = 400a   (the address of second, the shortest string)

D. 
(a) You have to state the test case.

(b) distance does not throw an IllegalArgumentException.

(a) Yes, the test case having s and t equal to the empty string has 
an expected return value of 0 but the implementation shown returns -1.

(b) No, because the method has a precondition that the strings s and t 
have the same length. We can't use the input strings s = "java" and 
t = "coffee" because we don't know what the expected return value should be. 

--------------------

Your submission:

A. THe final keyword means the field can only be assigned a value once. 
This doesn't always mean that the value can't be changed later, though.

B. a = "coffee", b = "java", c =

C.      There is no parameter for the second string s, only t.

        There are no listed preconditions for shortest() in the Javadoc.
        
        It is missing the @returns specification

D. a) A test case that checks to make sure the returned result is not equal to negative one
      would be one way to check if method was implemented correctly.
      
   b) We should use thowo strings because they are not equal in length, and thus it would be a way
                to test that the proper Illegal Argument Exception is being thrown.

--------------------