# P3: Recursion

Due Monday, July 6, 12:00 PM via Checkin
Late deadline, July 6, 11:59 PM
100 points

## 1. Objective

The objective of this assignment is to practice recursion. You will not get any points if you use loops (while, for, or do) in this program.

In a file called P3.java, write a Java class called P3, which contains the following methods.

• public String duplicateEachCharacter(String s)

This method duplicates each character in s and returns the result as a new String. For example, if the String "Ja~a" is the argument, then the result is JJaa~~aa. If s is an empty String, then the result is an empty String as well. If s is null, then the result is null.

• public int[] computeCumulativeSums(int[] numbers)

This method computes cumulative sums in the array numbers. Transform each value in the array by adding to the value the sum of values that precede it in the array. For example, if

```numbers = [5, 6, 7, 2, 3, 1],
```
then
```result = [5, (5)+6, (5+6)+7, (5+6+7)+2, (5+6+7+2)+3, (5+6+7+2+3)+1],
```
i.e.,
```result = [5, 11, 18, 20, 23, 24].
```

Assume that there is at least one value in the array numbers. We will not test your method with an uninitialized or empty array.

• public boolean searchTable(int[][] data, int element)

Given a 2D int array called data, return true if any value in the array equals element. Otherwise return false. Your program should work with arbitrarily sized arrays in either dimension, including ragged (or irregular) arrays. For example:

```int[][] table = new int[][] { {5, 2, 8, 5, 61}, {3, 9, 6}, {10, 42, 53, 45}};
searchTable(table, 45) returns true
searchTable(table, 100) returns false
```

## 3. General Information

None of the methods above should be declared static. In fact, compilation of your program will fail if the method signatures in your program are different than above. Do not hardcode any parameters into your methods. Test your program with test data in addition to what is already provided in the assignment.

Keep in mind that we will not test your main method -- the methods you implement will be tested directly. However, you should use your main to test the methods that you write. A barebones main can include something like:

```    public static void main(String [] args) {
P3 p = new P3();
System.out.println("duplicateEachCharacter(Ja~a) = " + p.duplicateEachCharacter("Ja~a"));
int[] numbers = new int[] {5, 6, 7, 2, 3, 1};
System.out.print("computeCumulativeSums(numbers) = ");
System.out.println(Arrays.toString(p.computeCumulativeSums(numbers)));
int[][] table = new int[][] { {5, 2, 8, 5, 61}, {3, 9, 6}, {10, 42, 53, 45}};
System.out.println(p.searchTable(table, 45));
System.out.println(p.searchTable(table, 100));
}
```

## 4. Submission

Submit the P3.java file via the online checkin system. This system performs preliminary testing of your program using the examples above. Final grading will be performed on a different set of data.