JAVA QUESTION If a user enters a date of birth in m/d/yyyy format how do you display it in mm/dd/yyyy format?
-
I have this code that is suppose to allow the user to either sort or search for what they input. It asks them first name, last name, and dob. However the code is suppose to be able to accept all types of date formats but when the sort or search if displayed it print the date in mm/dd/yyyy format. Here is what I have but I cant figure that one thing out. public static void main(String[] args) { int answer = 0; Scanner keyboard = new Scanner(System.in); System.out.println("How many people will you like to enter? "); int numPeople = keyboard.nextInt(); String firstName[] = new String[numPeople]; String lastName[] = new String[numPeople]; String dob [] = new String [numPeople]; for (int i = 0; i < numPeople; i++) { System.out.println("Enter first name, last name, and DOB in MM/DD/YYYY format : " ); firstName[i] = keyboard.next(); lastName[i] = keyboard.next(); dob[i] = keyboard.next(); } menuSelection(answer,firstName,lastName,… }//end main public static void menuSelection (int num, String [] firstName, String [] lastName, String [] dob){ Scanner keyboard = new Scanner (System.in); System.out.println(); System.out.println("\n" + "To search an entry enter 1. To sort a list enter 2. To exit enter 3: "); int answer = keyboard.nextInt(); if(answer == 1) { searchEntry(firstName,lastName,dob); } else if (answer == 2) { list(firstName,lastName,dob); } else { System.exit(0); } }//end menuSelection public static void searchEntry (String [] firstName, String [] lastName, String [] dob) { String name; int answer = 0; boolean flag; flag = false; Scanner keyboard = new Scanner (System.in); System.out.println("How will you like to search an entry? To search by First Name enter 1. " + "To search by Last Name enter 2. To search by Birth-date enter 3: "); int choice = keyboard.nextInt(); if (choice == 1) { System.out.println("Enter First Name to search: "); name = keyboard.next(); for ( int n = 0; n < firstName.length; n++) { if (firstName[n].equals(name)) { flag = true; System.out.println("You have searched for: " + firstName[n] + " " + lastName[n] + " " + dob[n] ); } } if (!flag) { System.out.println("Entry was not found"); } } else if (choice == 2) { System.out.println("Enter Last Name to search: "); name = keyboard.next(); for (int n = 0; n < lastName.length; n++) { if (lastName[n].equals(name)) { flag = true; System.out.println("You have searched for: " + firstName[n] + " " + lastName[n] + " " + dob[n] ); } } if (!flag) { System.out.println("Entry was not found"); } } else if (choice == 3) { System.out.println("Enter Birth-date to search: "); name = keyboard.next(); for (int n = 0; n < dob.length; n++) { if (dob[n].equals(name)) { flag = true; System.out.println("You have searched for: " + firstName[n] + " " + lastName[n] + " " + dob[n] ); } } if (!flag) { System.out.println("Entry was not found"); } } else { System.out.println("Input Error"); } menuSelection(answer,firstName,lastName,… }//end searchEntry public static void list (String [] firstName, String [] lastName, String [] dob){ int answer = 0; int ctr; int i;
-
Answer:
When you get the string that the user input, use the string functions to separate the string into the day month and year. It will then be easy to change it to the format you want then re-concatenate it before you add it into the array.
Berenice M at Yahoo! Answers Visit the source
Related Q & A:
- How To Know Your Future By Date Of Birth For Free?Best solution by my-fortune-teller.com
- How to check on all the permissions granted to a user and apply the same permissions to another user?Best solution by Stack Overflow
- How to change the date format yyyy/mm/dd to dd/mm/yyyy in below code?Best solution by scn.sap.com
- Changing a user on a BlackBerry?Best solution by supportforums.blackberry.com
- How to insert a date variable in java?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.