Problem 1:

Base case: num2 == 0 Recursive case: num2 != 0 Recursive step: result = num2*method(num2, num1/num2)

Problem 2: method(13,3) result = 1 result = 3*method(3, 4) result = 1 result = 4*method(4,0) result = 1 result = 4 return 4 return 16 return 48

The final result is 48.

Problem 3: public void multiplicationTableRecursive(int row, int col) { recursivelyPrintTable(row, col, col); } public void recursivelyPrintTable(int row, int col, int originCol) { if(row==0 && col==0){ System.out.print("*"); return; }

if(col==0){ recursivelyPrintTable(row-1, originCol, originCol); System.out.print(row); return; }

recursivelyPrintTable(row, col-1, originCol); if(row==0){ System.out.print(" " + col); } else { System.out.print(" " + col*row); }

if(col==originCol){ System.out.print("\n"); } }

Problem 4: Base case: (row==0 && col==0); Recursive case: else; recursive steps: if(col==0): recursivelyPrintTable(row-1, originCol, originCol); else: recursivelyPrintTable(row, col-1, originCol);

The symbols are printed after the coresponding recursive steps return. We start from the right- bottom element of the table. If it is not the first element in the row, col is reduced by 1 and go on with recursion. If it is the first element in a row, row is reduced by 1 and col is set to original col value.The recurrsion ends when it reaches the left-top element. Then we began to print out elements. The first is a "*". When we at the first row or column, we print the coresponding row/column index, else we print out the value of row*col. If we at the right end of a row, we print out an additional "\n".

Problem 5:

public static int powerRecursive(int base, int exp) { int result = 1;

if(base == 0) return 0;

if(exp == 0) result = 1; else result = base * powerRecursive(base, exp -1); return result;

}

Problem 6:

Base case: exp == 0 Recursive case: exp != 0 Recursive step: result = power(base, exp-1, base*result);

The variable result will be used to record the current value of exponentiation. At the very beginning, result is 1 and exp is user-defined. Each time you enter the recursive step, the exp will be decremented by 1, and result will be timed by the base. Only until exp becomes 0, the recursive step can be finished.

Problem 7:

class Number { private int value;

public Number() { value = 0; }

public Number(int value) { this.value = value; }

public int getValue() { return this.value; }

public void setValue(int value) { this.value = value; }

public String toString() { return "The private value is :" + this.value; } public void increment() { this.value++; }

public void reset() { this.value = 0; } }

Problem 8: class Driver { public Number num;

public static void main(String args[]) { Num = new Number();

boolean flag = true; while(flag) { System.out.println("a) Increment the number's value"); System.out.println("b) Print a string representation of the number"); System.out.println("c) Reset the number's value"); System.out.println("d) Quit"); System.out.print("Pleae make your choice: ");

char choice = UserInput.readChar();

switch(choice) { case 'a': num.increment(); break; case 'b': System.out.println(num.toString()); break; case 'c': num.reset(); break; case 'd': flag = false; break; } } } }

Problem 9: class IntegerNumber extends Number { }

Problem 10: String Holiday = new String("Class Break"); or String Holiday = "Class Break";

Problem 11: Holiday.subString(6);

Problem 12: Holiday.equalsIngoreCase("Spring Break");

Probelem 13: data.charAt(data.length()-1);

Problem 14: has a/aggregation lays a/association is a/inheritance washes/association has a/aggregation is a/inheritance