The following code runs a method called validateUser() that will throw an IllegalArgumentException if a username (passed
Question:
The following code runs a method called validateUser() that will throw an IllegalArgumentException if a username (passed in as a parameter) is less than three letters long. This method will not return any value and will do nothing if no error is thrown.
Below, a try/catch block has been implemented to make the username longer than 3 characters if it is too short.
Add in a finally block to add ".user" onto the end of each user name.
public String validUserName(String userName)
{
String result = userName;
String suffix = ".user";
try
{
validateUser(userName);
}
catch (IllegalArgumentException badUser)
{
while (result.length() < 3)
{
result += "*";
}
}
return result;
}
Building Java Programs A Back To Basics Approach
ISBN: 9780135471944
5th Edition
Authors: Stuart Reges, Marty Stepp