Currently in Object-Oriented Programming here. I'm required to prompt a user to input several particulars, including a Date of Birth in the DD/MM/YYYY format. Then, these particulars will be used to construct a Customer object to add to an ArrayList. The Date of Birth must be in a Calendar type to be used to construct a new Customer object.
Thing is, I don't have a lot of idea around Calendar. Here are my questions:
- How would I get a user input in a Calendar type?
- If what I just said is not achievable, what would?
- How do I prompt the user for a String date and then convert it to a Calendar?
I (kinda) know how to use date formatting, though I've no idea how to work around for a user input. Most of the stuffs I found on google and stack overflow doesn't relate to a user input (or it did and I just can't get my head around it). Here's my current code in question:
Scanner inputReg = new Scanner(System.in);
DateFormat df = new SimpleDateFormat("DD/MM/YYYY");
String IC = "";
String name = "";
String date = "";
Calendar dob = Calendar.getInstance();
String tel = "";
System.out.print("Enter Date of Birth (DD/MM/YYYY ): ");
date = inputReg.nextLine();
dob.setTime(date); //and here I'm stuck
System.out.println(dob);