I having an issue with my code skipping input fields in a loop when I select to enter in more data.
Below is my loop:
do {
System.out.println("****PLEASE ENTER DETAILS FOR PERSON "+count+"****");
count++;
System.out.print("Name: ");
name = keyboardIn.nextLine();
System.out.print("Gender: ");
gender = keyboardIn.next().charAt(0);
System.out.print("Age: ");
age = keyboardIn.nextInt();
keyboardIn.nextLine();
System.out.print("Occupation: ");
occupation = keyboardIn.nextLine();
System.out.print("Weight: ");
weight = keyboardIn.nextDouble();
System.out.print("Height: ");
height = keyboardIn.nextDouble();
//Add the person object to the ArrayList
personList.add(new Person(ppsNo++, name, age, gender, occupation, height, weight));
System.out.print("Would you like to add another person record (Y/N): ");
ans = keyboardIn.next().charAt(0);
} while (ans == 'y' || ans == 'Y'); //continue entering people if user enters y or Y
This is the output when I try to enter information for another person:
****PLEASE ENTER DETAILS FOR PERSON 1****
Name: Nevin O'Regan
Gender: M
Age: 43
Occupation: IT
Weight: 89
Height: 78
Would you like to add another person record (Y/N): Y
****PLEASE ENTER DETAILS FOR PERSON 2****
Name: Gender: