Exercise on Classes and Methods

You may wish to refer to Examples of Classes and Methods.

Suppose that there is an existing StringTransformer class and also the following:

     public interface StringTransformable {
         public String transform(String x);
     }

  1. Write a Pig class that extends StringTransformer and implements StringTransformable. A Pig's transform method takes a String and puts the word oink both before and after it. For example, given "I am a duck" it would produce "oink I am a duck oink".

  2. Write a Cheerleader class that extends StringTransformer and implements StringTransformable. A Cheerleader's transform method takes a String and puts an appropiate cheer both before and after it (as in the previous problem). Different Cheerleaders have different cheers, in general.

    For example, given the String "I am the walrus":

    while given the String "Coo-coo ch-choo" the same three Cheerleaders would produce, respectively: