CMPU 101 - Lab 12

$Revision: 1.2 $

In this lab you will define several recursive methods.

Getting Started

From the class webpage, download Lab12.java and Lab12Test.java.  Start DrJava and open both files.

Your Task

Your task is to implement the three methods in the Lab12 class.

The power method should recursively compute the value of a number n raised to a specified exponent.  Suggestion: the base case should occur when the exponent is 0: any number raised to the exponent 0 equals 1.

The powerTailRec method should also raise the number n to a specified exponent, but it should perform the computation using tail recursion.  You will need to define a recursive helper method that takes an additional accumulator parameter.

The stringToInt method takes a String containing digits and converts it to an integer value.  The suggested approach is to use the empty string as a base case (treating its integer value as 0), and use the String consisting of all digits except the last as the subproblem.  See the method comment for details.

Testing

The Lab12Test class contains JUnit tests for each method.  Click "Compile All" and then "Test" to run the JUnit test.

When You Are Done

Demonstrate that all of the JUnit tests pass, and also show your completed code to a lab coach or instructor.

Submit the file "Lab12.java" using the CS 101 Submission WebsiteMake sure you submit the Java source file: the filename should end in ".java", not ".java~" or ".class".