Question: I started my code but i keep getting an error. here is the assignment and screenshot of my code, please assist: ask the user for
I started my code but i keep getting an error.
here is the assignment and screenshot of my code, please assist:
ask the user for and read in their first and last name
use a loop to validate the first name: it must be at least one character long and it must start with a letter
use a loop to validate the last name: it must not contain any spaces and it must not be empty blank
Hint: use a nested loop. The outer loop will iterate until there is valid input. The inner loop will check each character in the String to see if any of them are whitespace. You also need to account for an empty name as invalid input.
Part Two: Generate a Username points
generate a twodigit random number ie a random number between and inclusive
create a username that is the following data concatenated:
the first letter of their first name in lower casethe first five characters of their last name in lower case; if the name is shorter than five characters, use the whole last namethe twodigit number
output the username to the user
public static void mainString args
Scanner an new ScannerSystemin;
Random rand new Random;
String firstName ;
String lastName ;
String userName ;
boolean passesTests false;
System.out.printlnWelcome to the Username Generator!";
while passesTests
System.out.printlnEnter your first name: ;
firstName scan.nextLine;
System.out.printlnEnter your last name: ;
lastName scan.nextLine;
boolean correctLength false;
boolean correctFirstLetter false;
boolean correctLastName false;
for int i ; i firstName.length; i
char ch firstName.charAti;
if CharacterisLetterfirstNamecharAtch
correctFirstLetter true;
passesTests correctFirstLetter && correctLength && correctLastName;
if passesTests && lastName. length
int ranNumber rand.nextInt;
char ch firstName. charAt;
char user Character.toLowerCasech;
String user lastName.substring;
userName user user ranNumber;
System.out.printlnYour username is: userName;
else if passesTests && lastName. length
int ranNumber rand.nextInt;
char ch firstName.charAt;
char user Character.toLowerCasech;
String user lastName;
userName user user ranNumber;
System.out.printlnYour username is: userName;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
