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


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;
}

 



Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!