Programming in Java Lab 2


In this lab you will write a function to reverse a name so that the last name comes first. For example, given the name Frodo Baggins, your function will change the name to Baggins, Frodo. Since some people have middle names, the function will have to handle names with middle initials, so the name Bilbo B. Baggins will be changed to Baggins, Bilbo B. The original name will be contained in one String object, as will the reversed version.

There may be more than one space between the parts of the name, but you can assume that a middle initial will always be followed by a period (.).

Your function should have one String parm, the original name. It should return a String which contains the reversed version of the name.

Write a main function which creates several names, calls your function to reverse each name, and prints both the original and reversed version of each of the names. Make sure you include some names with middle initials and some names without middle initials.


Email Me | Office Hours | My Home Page | Department Home | MCC Home Page