Next: Documentation
Up: Assignment 7: Strings and
Previous: Palindromes
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
``Downey, Allen.''
In order to compare names and put them in alphabetical order,
it is necessary to convert them into a common form.
- 1.
- Create a new project (no graphics) named Name.
- 2.
- 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
format.
- 3.
- 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
1999-03-17