This question involves analyzing strings. You will write the countRepeat method of the following StringAnalyzer class. public class StringAnalyzer { /** Returns a count of how many times smallstr occurs in largeStr, as described in part (a) Precondition: largeStr is not null; smallStr is not null. The length of smallstr is less than the length of largeStr. * */ public static int countRepeat (String largeStr, String smallstr) { /* to be implemented in part (a) */ } // There may be variables and methods that are not shown. } (a) The countRepeat method is used to count and return the number of times the string parameter smallstr appears in the string parameter largeStr. In the case of overlapping occurrences of smallstr, only the first occurrence is included in the overall count, as shown in the second and third calls to countRepeat in the following table of examples Return value 1 Call to countRepeat StringAnalyzer.countRepeat("BAAB", "AA") StringAnalyzer.countRepeat ("AAAAA", "AA") StringAnalyzer.countRepeat("AABABABAA", "ABA") StringAnalyzer.countRepeat ("ABBAABB", "ABA") 2 2 0 Complete method countRepeat. /** Returns a count of how many times smallstr occurs in largestr, as described in part (a) Precondition: largestr is not null; smallStr is not null. The length of smallstr is less than the length of largeStr. */ public static int countRepeat(String largeStr, String smallstr) (b) A programmer would like to modify the StringAnalyzer class to limit the length of the large string that can be passed as input to countRepeat. The limit could vary between calls to countRepeat. A call to countRepeat with a value of largeStr that is longer than the maximum length would return -1. The programmer would like to implement this change without making any changes to the signature of the countRepeat method or overloading countRepeat. Write a description of how you would change the stringAnalyzer class in order to support this modification. Do not write the program code for this change. Make sure to include the following in your response. • Identify any new or modified variables or methods. • Describe, for each new or revised variable or method, how it would change or be implemented, including visibility and type.



Answer :

Other Questions