The below code is meant to populate an arraylist of employee objects with user input (first name, last name, job title, and sex). During the second loop the code asks for the first name input again, like expected, but doesn't allow the user to input it, prompting the user to input for last name instead. What am I doing wrong?
for(int i = 0; i < 2; i++){ //LOOP MESSES UP SOMEHOW
//Get employee object first Name
System.out.println("First name: ");
fName = kb.nextLine();
//Get employee object last Name
System.out.println("\nLast name: ");
lName = kb.nextLine();
//Get employee object Job Title
System.out.println("\nJob Title: ");
job = kb.nextLine();
//Set employee object sex
while(loopControl){
System.out.println("\nSex: (Enter M for Male or F for Female)");
empSex = kb.next().charAt(0);
//Validate sex value input
if(empSex == 'M' || empSex == 'F'){
loopControl = false;
}
else{
System.out.println("Invalid entry. Enter M for Male or F for Female \n");
}
}
//Add populated employee object to ArrayList
employees.add(new EmployeeRegistry(fName, lName, job, empSex));
}