I am new in java so, can anybody help me with this java problem? Write a program that will accept ten (or more) names (first and last names) and associated birth-date. Your program should ask the user for how many people s/he wants to enter and then read the names (first and last) and the corresponding birth-date. The birth-date must be entered in the following format: MM/DD/YYYY. Your program should then use a menu that allows the user to display, search and exit. Display should display the list of the entries, sorted by last name, first name, or birth-date as requested by the user. Search should search for a specific entry by a specific field (last name, first name or birth-date) as requested by the user. Exit should terminate the program when the user selects exit from the menu.
pramila1988 · Sep 20, 2011 3:12 PM · 525 views
hi pramila988, You better understand first Java, your project will be easy then. So, follow this link: http://www.youtube.com/watch?v... There are more than 50 videos which is extremly good to learn Java.
Tmobile · Sep 20, 2011 3:45 PM
Hi. I wrote the code but i got an error and dont know how to fix it. there is a problem at the BirthDateDemo. Can any one help me to solve that error. thanks. import java.util.*; import java.text.SimpleDateFormat; class BirthDate { String fName; String lName; Date dob; public BirthDate() { dob=new Date(); } public BirthDate(String fn,String ln,String d)throws Exception { fName=fn; lName=ln; String DATE_FORMAT = "MM/dd/yyyy"; SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); dob=sdf.parse(d); } public String getFname() { return fName; } public String getLname() { return lName; } public String getDob() { return dob.toString(); } } public class BirthDateDemo { static BirthDate []bday; public static void main(String[] args)throws Exception { Scanner scan=new Scanner(System.in); int n; String fname,lname,dt; System.out.print("Enter number of names you want to enter?:"); n=scan.nextInt(); scan.nextLine(); bday=new BirthDate[n]; for(int i=0;i<n;i++) { System.out.print("Enter First Name:"); fname=scan.nextLine(); System.out.print("Enter Last Name:"); lname=scan.nextLine(); System.out.print("Enter Date of birth (MM/DD/YYYY):"); dt=scan.nextLine(); bday[i]=new BirthDate(fname,lname,dt); } int choice; do { System.out.println("1.Display"); System.out.println("2.Search"); System.out.println("3.Exit"); System.out.print("Enter Your Choice:"); choice = scan.nextInt(); switch(choice) { case 1: int displayChoice; System.out.println("1.By First Name"); System.out.println("2.By Last Name"); System.out.println("3.By Date"); System.out.print("Enter Choice: "); displayChoice = scan.nextInt(); scan.nextLine(); switch(displayChoice) { case 1:BirthDateDemo.sortByFName(n);break; case 2:BirthDateDemo.sortByLName(n);break; case 3:BirthDateDemo.sortByDate(n);break; } BirthDateDemo.display(n);break; case 2: int searchChoice; System.out.println("1.By First Name"); System.out.println("2.By Last Name"); System.out.println("3.By Date"); System.out.print("Enter Choice: "); searchChoice = scan.nextInt(); scan.nextLine(); System.out.print("Enter Search Key"); String key=scan.nextLine(); switch(searchChoice) { case 1:BirthDateDemo.searchByFname(key, n);break; case 2:BirthDateDemo.searchByFname(key, n);break; case 3:BirthDateDemo.searchByDate(key, n); break; } break; case 3:System.exit(0); } }while(choice!=3); } public static void searchByFname(String fname,int n) { boolean flag=false; for(int i=0;i<n;i++) { if(bday[i].getFname().equalsIgnoreCase(fname)) { System.out.println("First Name:" +bday[i].getFname()); System.out.println("Last Name: "+bday[i].getLname()); System.out.println("Date of Birth :"+bday[i].getDob()); flag=true; break; } } if(!flag) { System.out.println("Record Not Found"); } } public static void searchByLname(String lname,int n) { boolean flag=false; for(int i=0;i<n;i++) { if(bday[i].getLname().equalsIgnoreCase(lname)) { System.out.println("First Name:" +bday[i].getFname()); System.out.println("Last Name: "+bday[i].getLname()); System.out.println("Date of Birth :"+bday[i].getDob()); flag=true; break; } } if(!flag) { System.out.println("Record Not Found"); } } public static void searchByDate(String dob,int n)throws Exception { Date d=new Date(); String DATE_FORMAT = "MM/dd/yyyy"; SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); d=sdf.parse(dob); boolean flag=false; for(int i=0;i<n;i++) { if(bday[i].getDob().compareTo(d.toString())==0) { System.out.println("First Name:" +bday[i].getFname()); System.out.println("Last Name: "+bday[i].getLname()); System.out.println("Date of Birth :"+bday[i].getDob()); flag=true; break; } } if(!flag) { System.out.println("Record Not Found"); } } public static void sortByFName(int n) { BirthDate temp=new BirthDate(); boolean flag=false; for(int i=0;i<n-1;i++) { for(int j=0;j<n-1-i;j++) { if(bday[j].getFname().compareTo(bday[i+1].getFname())==1) { temp=bday[i]; bday[i]=bday[i+1]; bday[i+1]=temp; flag=true; } } if(!flag) break; } } public static void sortByLName(int n) {  
pramila1988 · Sep 26, 2011 7:12 PM
rest of the code. BirthDate temp=new BirthDate(); boolean flag=false; for(int i=0;i<n-1;i++) { for(int j=0;j<n-1-i;j++) { if(bday[j].getLname().compareTo(bday[i+1].getLname())==1) { temp=bday[i]; bday[i]=bday[i+1]; bday[i+1]=temp; flag=true; } } if(!flag) break; } } public static void sortByDate(int n) { BirthDate temp=new BirthDate(); boolean flag=false; for(int i=0;i<n-1;i++) { for(int j=0;j<n-1-i;j++) { if(bday[j].getDob().compareTo(bday[i+1].getDob())==1) { temp=bday[i]; bday[i]=bday[i+1]; bday[i+1]=temp; flag=true; } } if(!flag) break; } } public static void display(int n) { for(int i=0;i<n;i++) { System.out.println("First Name:" +bday[i].getFname()); System.out.println("Last Name: "+bday[i].getLname()); System.out.println("Date of Birth :"+bday[i].getDob()); System.out.println(); } } }
pramila1988 · Sep 26, 2011 7:15 PM
K error, Unparseable dateException? khai ta, I ran it , chalirachha ta?? Be more specific..
Duderino · Sep 26, 2011 8:12 PM
thnks for the replay. and kasari chalyo? when i run it it says The public type BirthDateDemo must be defined in its own file.
pramila1988 · Sep 26, 2011 8:46 PM
What is your class name?
Duderino · Sep 26, 2011 8:55 PM
Duderino · Sep 26, 2011 9:01 PM
I think you have problem with file name. Save the FileName as BirthDateDemo.java and compile n run. compile $javac BirthDateDemo.java run $java BirthDateDemo
DalluKoSanu · Sep 26, 2011 10:04 PM
Your java file name should be BirthDateDemo.java or create a package with two java file BirthDate.java BirthDateDemo.java Last edited: 26-Sep-11 10:09 PM
serial · Sep 26, 2011 10:04 PM
This conversation is preserved exactly as it was on the original Sajha.com and can't accept new replies.
Start a New Discussion