0

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);
  }
}

enter image description here 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 ?

Zachary Dale
  • 739
  • 4
  • 11
  • 30
  • you already asked a similar question here http://stackoverflow.com/questions/41881501/take-date-input-from-user-and-save-it-as-date-in-java so please continue with one question you can make comment and you can edit your post – Youcef LAIDANI Jan 26 '17 at 20:43
  • Couldn't find solution. I also added `scan.nextLine();` in place of `input.nextLine(); ` as suggested in the above mentioned (duplicate) but it gives me warning cannot find symbol `scan` and to create scan class. – Zachary Dale Jan 26 '17 at 20:57
  • scan is the same with your input thats all – Youcef LAIDANI Jan 26 '17 at 20:58
  • can you elaborate it with example please. like `scan.nextLine();` ? – Zachary Dale Jan 26 '17 at 21:00
  • return to your first question http://stackoverflow.com/questions/41881501/take-date-input-from-user-and-save-it-as-date-in-java so we can help you this question is already closed – Youcef LAIDANI Jan 26 '17 at 21:02
  • did you tried my solution here : http://stackoverflow.com/a/41881678/5558072 – Youcef LAIDANI Jan 26 '17 at 21:03

0 Answers0