Activity 10.1.1.
Finish writing the
StringCoder method decodeString.https://apstudents.collegeboard.org/courses/ap-computer-science-a/free-response-questions-by-year"sixtyzipperswerequicklypickedfromthewovenjutebag". This string and its indexes are shown below.
"overeager" is encoded as the list of string parts [ (37, 3), (14, 2), (46, 2), (9, 2) ] denoting the substrings "ove", "re", "ag", and "er".StringPart class shown below.public class StringPart
{
/**
* @param start the starting position of the substring in a master string
* @param length the length of the substring in a master string
*/
public StringPart(int start, int length)
{
/* implementation not shown */
}
/**
* @return the starting position of the substring in a master string
*/
public int getStart()
{
/* implementation not shown */
}
/**
* @return the length of the substring in a master string
*/
public int getLength()
{
/* implementation not shown */
}
// There may be other instance variables, constructors, and methods
}
StringCoder provides methods to encode and decode words using a given master string. When encoding, there may be multiple matching string parts of the master string. The helper method findPart is provided to choose a string part within the master string that matches the beginning of a given string.public class StringCoder
{
private String masterString;
/**
* @param master the master string for the StringCoder Precondition: the master
* string contains all the letters of the alphabet
*/
public StringCoder(String master)
{
masterString = master;
}
/**
* @param parts an ArrayList of string parts that are valid in the master
* string Precondition: parts.size() > 0
* @return the string obtained by concatenating the parts of the master string
*/
public String decodeString(ArrayList<StringPart> parts)
{
/* to be implemented in part (a) */
}
/**
* @param str the string to encode using the master string Precondition: all of
* the characters in str appear in the master string; str.length() > 0
* @return a string part in the master string that matches the beginning of
* str. The returned string part has length at least 1.
*/
private StringPart findPart(String str)
{
/* implementation not shown */
}
/**
* @param word the string to be encoded Precondition: all of the characters in
* word appear in the master string; word.length() > 0
* @return an ArrayList of string parts of the master string that can be
* combined to create word
*/
public ArrayList<StringPart> encodeString(String word)
{
/* to be implemented in part (b) */
}
// There may be other instance variables, constructors, and methods
}
StringCoder method decodeString. This method retrieves the substrings in the master string represented by each of the StringPart objects in parts, concatenates them in the order in which they appear in parts, and returns the result.decodeString method.StringCoder method decodeString.