ICS 111 Homework Assignment H12: Recursion, Anagrams

Purpose

We are going to continue our problem-solving education by introducing recursion. Recursion is a powerful problem-solving tool. We will write a program that prints all the anagrams of a given string. This will help us understand recursion and subroutines.

We will also get more practice using Eclipse to make our programming life easier.

Tasks

1. Create a package named edu.ics111.h12 in your project

This is where we will put all our classes for homework 12.

2. Write a program that lists all the rearrangements of a word entered by the user.

The program’s name is PrintAnagrams.

The program must have a recursive method

void printAnagrams(String prefix, String word);

The recursive printAnagrams algorithm looks something like.

if word length is one
  Print the prefix and word.
else
  For each letter in the word:
    Print the prefix + letter followed by the rearrangements of the word without the letter.

For example if the user entered the string “bar”. The program should output:

bar
bra
abr
arb
rba
rab

You may want to try a longer string, but it may take a while to run.

Grading Rubric

CriterionExcellent (100%)Satisfactory (75%)Borderline (50%)Unsatisfactory (25%)Poor (0)
Adherence to standards - 2 points
Does it conform to standards in every detail?
No errors. Minor details of the assignment are violated, or poor choices are made where the assignment is unclear. Significant details of the assignment or the underlying program intent are violated, but the program still fulfills essential functions. Significant details of the assignment or the underlying program intent are violated, but the program still fulfills some essential functions. Misses the point of the assignment.
Breakdown (modular design) - 2 points
Does it demonstrate good modular design?
No errors. 1-3 minor errors. > 3 minor errors OR 1 major error. 2 major errors > 2 major error.
Correctness of code - 4 points
Does it work? Does it pass JUnit?
Passes all tests. Works for typical input, may fail for minor special cases. Fails for typical input, for a minor reason. Fails for typical input, for a major reason. No.
Documentation, and style - 2 points
Is it clear and maintainable? Does it pass CheckStyle?
No errors. 1-3 minor errors. > 3 minor errors OR 1 major error. 2 major errors > 2 major error.

Turning in the Assignment

The assignment is due on Wenesday, December 8th at 11:55pm. You may turn it in early.