* Sets the name of this person to the given name.
* The name must be of non-zero length and consist of only letters and at most one blank, which cannot
* be the first or last character.
* @param name - The new name of this person.
* @throws java.lang.IllegalArgumentException - if the passed name is not allowed.
*/
public void setName(java.lang.String name) throws java.lang.IllegalArgumentException
{
int numSpaces;
for (int i = 0; i < name.length(); i++)
{
if (name.substring(i, i + 1) == " ")
{
numSpaces++;
}
}
if (name.length() != 0 && name.substring(0, 1) != " " && numSpaces <= 1 && name.substring(name.length() - 1) != " ")
{
this.name = name;
}
else
{
throw new IllegalArgumentException();
}
}
no
setName
public void setName(java.lang.String name)
throws java.lang.IllegalArgumentException
Sets the name of this person to the given name.
The name must be of non-zero length and consist of only letters and at most one blank, which cannot be the first or last character.
Parameters:
name - The new name of this person.
Throws:
java.lang.IllegalArgumentException - if the passed name is not allowed.