Work on this exercise by yourself, but be quick to ask questions of your instructor, student assistants and classmates as desired.
GoalsSolidify your understanding of how to:
|
Grading rubricStudents write 10 classes that implement StringTransformable. Each class is worth 10 points, for a total of 100 points. For each of those 10 classes:
The grader will not grade the documentation for the JUnit test classes (the existing tests are already documented). Students should use good style in writing tests in the JUnit test classes. For any points deducted, the grader will put a CONSIDER tag saying how many points were deducted and why. “Earn back” is available for this assignment.
Here is a link to the General Instructions for Grading Programs. |
/** * A StringTransformable object can transform one String into another String. * * @author David Mutchler, based on an idea from Lynn Stein in her Rethinking CS * 101 project. Created March 12, 2009, updated December 3, 2010. */ public interface StringTransformable { /** * Transforms the given String into another String and returns the * transformed String. Does NOT modify the given String (indeed, cannot * modify it, since Strings are immutable). * * @param stringToTransform * The String to transform * @return The transformed String */ public String transform(String stringToTransform); } |
Examine your WordGames project and note that the StringTransformable interface is already added to the project.
Shouter:
given blah,
produces the result of changing all the characters in
blah to upper-case.
|
Censor:
given blah,
produces the result of replacing each occurrence of the character (not string)
foo in blah with an asterisk,
where foo is the character that the particular Censor censors.
Reminder: Your code must obey the StringTransformable interface.
|
Pedant:
puts "Obviously " before its given string.
|
NameDropper:
puts "foo says "
before its given string,
where foo is the name that the particular NameDropper drops.
For NameDropper, we supplied ONLY tests for NameDroppers that drop the default name (Madonna). YOU must supply tests for NameDroppers that drop a non-default name.
|
Counter:
puts a number in front of each input, that goes 1, 2, 3, ...
For Example:
A good way to functionally test this class is to:
|
Doubler:
repeats the given string two times, with a single space in between.
|
SlowThinker:
produces whatever it was given the previous time.
For example:
As with Counter (and indeed, as with all these StringTransformers), each instance of SlowThinker is independent of other instances of SlowThinker. This one is challenging! Don't spend more than 30 minutes on its code (unless you want to!). |
SometimesShouter:
has a positive whole number (I'll call it n).
The SometimesShouter capitalizes every
nth String that it is given (and leaves other Strings unchanged).
Each SometimesShouter has its own number (so n should be a field that can be set using a constructor. If it is not told about any such number, it will use 2 (capitalizing every other string it is given) by default. For example:
Just ask if you have questions about what a SometimesShouter is supposed to do. |
Repeater:
transforms the given String into N copies of the given String,
where N is the length of the given String.
For example:
Another example:
|
Evener:
transforms the given String into
a String consisting of only the characters whose positions in the given string are even.
For example:
Note that in the above definition, the first character's position is “even”, because we start numbering from 0 (as in the C language) and we consider 0 to be an “even” number. |
UbbiDubbier:
transforms the given String into Ubbi Dubbi.
|