Question: 3. The Java program compress below takes two parameters: a strings and an integer factor, which indicates how many consecutive occurences of any character c

 3. The Java program compress below takes two parameters: a strings

3. The Java program compress below takes two parameters: a strings and an integer factor, which indicates how many consecutive occurences of any character c should be compressed in the form on where n is the number of consecutive occurrences of c. The program compresses the input strings by the given compression factor and return the re- sulting compressed string. For example, given the input string 'abba and a factor the resulting compressed string will be azar, but it the factor is instead, then the sequence of two a's is not compressed and the resulting string will be 'aab 2 2 + 5 . 30 public statie String compress Strings, int factor) if factor throw new fliegalArgumentException compression factor must be if (silength() 21 returns char lant - chart int count - 1 String current - String.valceo (last: String result - for (int i = . Longit ++ char och 1 Last current count else It count factor result last + String Valceatcount); : else result current Last - current - String.value) count -11 18 23 1count > factor result - last string count) else result current return result (a) Measurement: Draw a control flow graph for the given program and compute its cyclomatic complexity. [10 marks] (b) Coverage: Write exactly four test cases and indicate which lines of code each of them covers. Use the following table as template for your tests. You are not required to write JUnit test code. [10 marks) factor Expected Output Lines covered value for value for factor expected return value e.g. 1-3, 4, 6-9 , 1 5 2 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!