Arrays

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ljungmichel
    New Member
    • Feb 2007
    • 3

    Arrays

    I really need some help with my project. It should be a very easy program, but no matter what I read online or in my books, I don't seem to be able to grasp the idea of arrays. I don't get how to use them at all.

    Here's the program:

    Write a program that will accept up to ten 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 in the following format: MM/DD/YYYY. Your program should then use a menu that allows the user to select either the way s/he wants to display the list of the entries, sorted by last name, first name, or birth-date, or to search for a specific entry by a specific field (last name, first name or birth-date) from data entered by the user. The program should terminate when the user selects exit from the menu.

    I've gotten as far as asking the user how many people they want to enter in. When you use JOptionPane, how does the variable that the user enters get stored in the array? Like what syntax do I need to use? Also, how the heck am I supposed to convert the birth date to the mm/dd/yyyy format? Any help would be appreciated! Remember, I'm dumb at this, so explain in easy terms please! THANKS!!
  • ljungmichel
    New Member
    • Feb 2007
    • 3

    #2
    Code:
    import javax.swing.JOptionPane;am?", "Number of people", JOptionPane.QUESTION_MESSAGE);
    
    	numPeople = Integer.parseInt(numberOfPeople);
    			
    	int count = 0;
    	String[] firstName = new String[numPeople];
    	String[] lastName = new String[numPeople];
    	int[] birthdate = new int[numPeople];
    			
    			
    		if(count <= numPeople)
    		{
    That's all I have so far. What I want to do next is ask the user the first person's last name and store it into the lastName array... but I'm not sure how to go about doing that.

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by ljungmichel
      Code:
      import javax.swing.JOptionPane;am?", "Number of people", JOptionPane.QUESTION_MESSAGE);
       
      	numPeople = Integer.parseInt(numberOfPeople);
       
      	int count = 0;
      	String[] firstName = new String[numPeople];
      	String[] lastName = new String[numPeople];
      	int[] birthdate = new int[numPeople];
       
       
      		if(count <= numPeople)
      		{
      That's all I have so far. What I want to do next is ask the user the first person's last name and store it into the lastName array... but I'm not sure how to go about doing that.
      Ok. Go back a little and start right at the basics. Write a class with the appropriate class name and put in a blank main method. Include also the neccessary import statements and correctly put these on the top of the class. Post after you get it to compile or if you get any problems doing that. The packages you need to import are javax.swing.* and either java.util.* or java.io.*

      Comment

      • ljungmichel
        New Member
        • Feb 2007
        • 3

        #4
        Oh, I'm sorry. I actually have done that. I didn't realize that I had copied and pasted something weird like that... Dunno why it came out like that.

        I found out that I should create class that defines a person instead of creating 3 separate arrays for the last name and first name and birth date. But I honestly don't know how to even start doing that. I could really use some help...

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Originally posted by ljungmichel
          Oh, I'm sorry. I actually have done that. I didn't realize that I had copied and pasted something weird like that... Dunno why it came out like that.

          I found out that I should create class that defines a person instead of creating 3 separate arrays for the last name and first name and birth date. But I honestly don't know how to even start doing that. I could really use some help...
          Yes it's much better to have a person class. Write that and put the required fields. You will need to give it at least two constructors. If you are not sure how to do that, read the third class here

          Comment

          • hirak1984
            Contributor
            • Jan 2007
            • 316

            #6
            May I ask you what have you extended?

            JApplet or JFrame?

            Originally posted by ljungmichel
            Oh, I'm sorry. I actually have done that. I didn't realize that I had copied and pasted something weird like that... Dunno why it came out like that.

            I found out that I should create class that defines a person instead of creating 3 separate arrays for the last name and first name and birth date. But I honestly don't know how to even start doing that. I could really use some help...

            Comment

            Working...