I have the following code to take the input from the user under case 1 of switch statement:
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
SimpleDateFormat myFormat = new SimpleDateFormat("dd MM yyyy");
Guest gstObject = new Guest();
System.out.println("Enter reservation ID:");
gstObject.setId(input.nextInt());
System.out.println("Enter first name:");
gstObject.setfName(input.next());
System.out.println("Enter last name:");
gstObject.setfName(input.next());
System.out.println("Enter check-in date (dd/mm/yy):");
String cindate = input.nextLine();
if(null != cindate && cindate.trim().length() > 0){
Date date1 = myFormat.parse(cindate);
}
System.out.println("Enter check-out date (dd/mm/yy):");
String outdate = input.nextLine();
if(null != outdate && outdate.trim().length() > 0){
Date date2 = myFormat.parse(outdate);
}
}
The code takes input one by one simultaneously upto
Enter last name:
but runs last two check-in date
and check-out date
step at once and doesn't ask for input of the check-in date
.
I tried by switching places of these input. I also ignores to take input that is on the top and takes input that is at the bottom. Also tried by placing check-in date
and check-out date
at the very top turnwise. They ignore to take inputs and jumps directly to Enter reservation ID
.
How can i solve this matter ?