|Our system has thousands of users, each with a unique User Id. When a
new user needs an id, we want to assign his User Id based on his first,
middle, and last name.
We do not want to assign a User Id if the names were incorrectly entered.
If the names are unreasonable we will return "BAD DATA". A name is judged
to be unreasonable if it contains a character other than a letter ('a'-'z' or 'A'-'Z'),
an apostrophe ''', or a space character ' '. It is also unreasonable if the first or
last name contains less than 2 letters ('a'-'z' or 'A'-'Z').
The algorithm for choosing a User Id is to choose the first rule below
that produces a User Id that has not already been assigned to another user.
In each case, truncate the last name as needed so that the resulting User Id
is no longer than 8 characters.
- [first initial][last name]
- [first initial][middle initial][last name]
- [first initial][last name][digit][digit]
Before we form the User Id, we will simply eliminate all apostrophes and space
characters, and will change all uppercase letters to lowercase. If there is no middle
name (or if the middle name contains no letters) then we must skip the second rule.
When we apply the third rule, we will try the digit pairs in order starting
with 01 then 02 etc. until we find a previously unused User Id.
Create a class UserId that contains method id that takes a String inUse
containing all the User Id's that have already been assigned and Strings first,
middle, and last as input. It will return "BAD DATA" if the name data is
unreasonable, or will return the User Id generated by our algorithm.