Perform a Code Walkthrough of the two programs given in this file. Include in your solution:
* A brief description of what each programs does.
* State the base case(s), recursive case(s), recursive step(s) utilized in every method implemented.
* An expression of how the recursive step is progressing the execution toward the base case in every method implemented.
* An expression of each state that develops as you move into and back out of the recursion of every method implemented.
import java.util.ArrayList;
class Assignment11ProgramA {
public static void main(String args[]) {
ArrayList list = new ArrayList();
list.add(new Integer(1));
list.add(new Integer(2));
list.add(new Integer(3));
list.add(new Integer(4));
list.add(new Integer(5));
System.out.println("Result: " + method(list));
}
public static int method(ArrayList list) {
int value = 0;
if (list.size() > 0) {
value = list.remove(0) + method(list);
}
return value;
}
}
class Assignment11ProgramB {
public static void main(String args[]) {
method(6);
}
public static void method(int number) {
method(number, 0);
}
public static void method(int number, int first) {
if (first < (number / 2) ) {
helper(number, first, 0);
method(number, first + 1);
helper(number, first, 0);
}
else if ( ((number % 2) == 1) && (first == (number / 2) ) ) {
helper(number, first, 0);
}
}
public static void helper(int number, int first, int second) {
if (second == first) {
System.out.println("*");
}
if (second < first) {
System.out.print("**");
helper(number, first, second + 1);
}
}
}