Introduction

This lab is intended to help you THINK clearly about recursion. It is more about THINKING than CODING. The actual code for the first two tasks is not extensive. If you find yourself writing lots of code, you've likely gone astray in your thinking. The third task will require a bit more coding, but still not a lot.

Specific requirements

  1. For each task, submit working java code that implements recursive methods and performs according to specification.
  2. Public methods should exactly match specification below for name, return type, and arg type(s)
  3. All code should be properly documented with javadoc-format comments. Include javadoc comments for each class, each method, and each data member.
  4. Generate html documentation using the javadoc command (See me or a peer if you need help with javadoc)
  5. Include an lab report (*.doc format). The report should contain three main sections (for the three tasks); each of the three sections should have the following five subsections: Problem Statement, Program Flow, Classes Needed, Discussion, and Project Code.

Task 1

Lafore exercise 6.1. Write a java program to perform multiplication by recursively calling a method that uses addition. Include a main() method that demonstrates how it works with several different values.

public long multiply(long x, long y) {...}

Task 2

Lafore exercise 6.3. Implement exponentiation using a recursive approach. Include a main() method that demonstrates how it works with several different values.

public long power(long base, int exponent) {...}

Task 3

Write a java program using recursion to check a string to see if it is a palindrome. Ignore punctuation, capitalization, spaces, and any other non-alphabetic characters -- in other words, remove them from the string before checking. (thus a phrase like "Madam, I'm Adam" should be ruled a palindrome, even though it's precise reverse would be the nonsensical "madA m'I ,madaM") Then use the following logic to check for palindromicity: the empty string is a palindrome; any single alphabetic character is a palindrome; a string a$b is a palindrome if a=b and $ is a palindrome. Note: use recursion rather than iteration.

Write a main method that repeatedly prompts the user for input, checks whether the input is a palindrome, and informs the user of the result. Terminate if the user enters a single period '.' as the input. The user prompt should notify the user of this special termination char.

public boolean isPalindrome(String phrase) {...}

 

Submission

  1. Submit your assignment as a single .zip archive file titled LAB06_lastname.zip. It should include working, documented java code as well as the lab report.
  2. Submit via sakai.messiah.edu | COSC282 | Assignments | Lab06.
Copyright © 1999-2008| Gene Rohrbaugh | Privacy Statement