Tuesday, 17 September 2013

without using if statement, how to generate a username in java

without using if statement, how to generate a username in java

Okay, my class assignment is to write a code to generate a username. But,
it can be no more than 7 letters of the last name. if there are fewer than
7 letters in the last name, then all the letters would be used. BUT the
prof says no if statements. Any ideas? The one I wrote works fine for
names 7 or more letters but sends an error for short last names. Here it
is:
//find first initial of firstName
char firstInitial = firstName.charAt(0);
//limit last name in userName to 7 characters
String shortLastName = lastName.substring(0, 7);
//create a username using the first letter of firstName and lastName
(but no more than 7 letters)
String userName = (firstInitial + shortLastName);
//print username in lowercase
System.out.println((firstName + " " + lastName + "'s standard username
is:" + userName).toLowerCase())
Really just need an idea of how to proceed. Possibly an example to look
at. I've about given up....

No comments:

Post a Comment