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 (10 points)
generate a two-digit random number (i.e., a random number between 10 and 99, 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 two-digit number
output the username to the user
public static void main(String[] args){
Scanner an_= new Scanner(System.in);
Random rand = new Random();
String firstName ="";
String lastName ="";
String userName ="!;
boolean passesTests = false;
System.out.println("Welcome to the Username Generator!");
while (!passesTests){
System.out.println("Enter your first name: ");
firstName = scan.nextLine();
System.out.println("Enter your last name: ");
lastName = scan.nextLine();
boolean correctLength = false;
boolean correctFirstLetter =false;
boolean correctLastName = false;
for (int i =0; i firstName.length(); i++){
char ch = firstName.charAt(i);
if (Character.isLetter(firstName.charAt(ch))){
correctFirstLetter = true;
}
passesTests = correctFirstLetter && correctLength && correctLastName;
if (passesTests && lastName. length()>5){
int ranNumber = rand.nextInt(89)+10;
char ch1= firstName. charAt(0);
char user1= Character.toLowerCase(ch1);
String user2= lastName.substring(1,5);
userName = user1+ user2+ ranNumber;
System.out.println("Your username is: "+ userName);
} else if (passesTests && lastName. length()5){
int ranNumber = rand.nextInt(89)+10;
char ch1= firstName.charAt(0);
char user1= Character.toLowerCase(ch1);
String user2= lastName;
userName = user1+ user2+ ranNumber;
System.out.println("Your username is: "+ userName);
I started my code but i keep getting an error.

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!