Up: Assignment 7: Strings and
When names are recorded in a computer, they are sometimes
written with the first name first, like ``Allen Downey,'' and
sometimes with the last name first and a comma, like
In order to compare names and put them in alphabetical order,
it is necessary to convert them into a common form.
- Create a new project (no graphics) named Name.
- Write a method called hasComma that takes a name as an
argument and that returns a boolean indicating whether it contains a
comma. If it does, you can assume that it is in last name first
- Write a method called convertName that takes
a name as an argument. It should check whether it contains a
comma. If it does, it should just return the string.
If not, then it should assume that the name is in first name first
format, and it should return a new string that contains the name
converted to last name first format.
Allen B. Downey