Exercise on Transformers

You may wish to refer to these examples of Transformers.

  1. Write the transform method for a Transformer whose rule is to return the first letter of any String it is given.

    After working this problem, check your answer by following this link.

  2. Write the transform method for a Transformer whose rule is to double whatever string it is given. For example, if it is given "Hubba", it returns "HubbaHubba".

  3. Write the transform method for a Transformer whose rule is to take a Rose-Hulman student's first, middle and last names as separate parameter inputs, and return the student's system username. Recall that RHIT usernames are the first six letters of the student's last name followed by their first and middle initials. (Ignore the issues of duplicate usernames, as from John Axon Smith and Jill Aggy Smith.)

  4. Write the entire class for a Transformer that welcomes new students to school by producing a message like "Welcome to Rose-Hulman Andy." The Transformer's transform method is only given a single parameter, the individual's name. However, the Transformer should be designed to make it possible to work for any school.

  5. Write the transform method for a Transformer whose rule is to take a String and return that String but with the first half all in upper case and the last half all in lower case. (If the String has an odd number of characters, the middle character should become lower case.) Hint: you are allowed to use the parameter name more than once in the body of the method.