Implement the Test5E class. A skeleton can be found here. The API can be found here.
package test5;
import java.util.List;
public class Test5E
{
/**
* Returns the maximum of the digits of the given string.
*
* @param digits a string consisting of only digits.
* @pre. digits.length() > 0 && digits consists of only digits.
* @return the maximum of the digits of the given string.
*/
public static int max(String digits)
{
int max;
if (digits.length() == 1)
{
max = digits.charAt(0) - '0';
}
else
{
max = Math.max(digits.charAt(0) - '0', Test5E.max(digits.substring(1)));
}
return max;
}
/**
* Returns the length of the concatenation of the strings of the given list.
* For example, for the list ["this", "is", "the", "last", "test"] the
* length is 17.
*
* @param sentence a list of strings.
* @pre. sentence != null
* @return the length of the concatenation of the strings of the given list.
*/
public static int length(List sentence)
{
return Test5E.length(sentence, 0);
}
/**
* Returns the length of the concatenation of the strings of the
* sub list of the given list starting at the given begin index.
* For example, for the list ["this", "is", "the", "last", "test"]
* and the begin index 2, the length is 11.
*
* @param sentence a list of strings.
* @pre. sentence != null
* @param begin the begin index of the sub list
* @pre. begin >= 0 && begin <= list.size()
* @return he length of the concatenation of the strings of the
* sub list of the given list starting at the given begin index.
*/
public static int length(List sentence, int begin)
{
int length;
if (begin == sentence.size())
{
length = 0;
}
else
{
length = sentence.get(begin).length() + Test5E.length(sentence, begin + 1);
}
return length;
}
}
/**
* Returns n + 4, where n is the given integer.
*
* @param n an integer.
* @pre. n >= 0.
* @return n + 4.
*/
public static int recursive(int n)
{
if (n == 0)
{
return 4;
}
else if (n == 1)
{
return 5;
}
else
{
return recursive(n - 2) + 2;
}
}