Problem: Taking input from the user with scanner (sc), and if I don't user a blank sc.nextLine(), the previous line will be skipped. If I do use this blank fire, the variable is never collected for later use.
System.out.println("Please enter the Airline name: ");
String airName = sc.nextLine();
sc.nextLine(); <---------
System.out.println("Please enter the Airline code: ");
String airCode = sc.nextLine();
System.out.println("Please enter the Delta Aircraft: ");
String airCraft = sc.nextLine();
System.out.println("Please enter the first class seat capacity: ");
int firstClass = sc.nextInt();
System.out.println("Please enter the business class seat capacity: ");
int busiClass = sc.nextInt();
System.out.println("Please enter the economy class seat capacity: ");
int econClass = sc.nextInt();
System.out.println("Airline name: " + airName);
System.out.println("Airline code: " + airCode);
System.out.println("Delta Aircraft: " + airCraft);
//Splitting the first word from the rest of the string
String arr[] = airCraft.split(" ", 2);
String firstWord = arr[0];
System.out.println(firstWord + " first class seat capacity: " + firstClass);
System.out.println(firstWord + " business class seat capacity: " + busiClass);
System.out.println(firstWord + " economy class seat capacity: " + econClass);
//Airline object
A8AirlineAircraftData airline = new A8AirlineAircraftData(airName, airCode, airCraft, firstClass, busiClass, econClass);
System.out.println(airName + " successfully added. Press Enter to continue.");
sc.nextLine();//Press Enter to continue
sc.nextLine();
//A8MainMenu.mainMenu(sc); //return to main menu after Enter.
return airline;
My output now:
Airline name:
Airline code: QA
Delta Aircraft: Boeing 787
Boeing first class seat capacity: 16
Boeing business class seat capacity: 25
Boeing economy class seat capacity: 199
successfully added. Press Enter to continue.