473,385 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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!!
Feb 19 '07 #1
5 1459
Expand|Select|Wrap|Line Numbers
  1. import javax.swing.JOptionPane;am?", "Number of people", JOptionPane.QUESTION_MESSAGE);
  2.  
  3.     numPeople = Integer.parseInt(numberOfPeople);
  4.  
  5.     int count = 0;
  6.     String[] firstName = new String[numPeople];
  7.     String[] lastName = new String[numPeople];
  8.     int[] birthdate = new int[numPeople];
  9.  
  10.  
  11.         if(count <= numPeople)
  12.         {
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.
Feb 19 '07 #2
r035198x
13,262 8TB
Expand|Select|Wrap|Line Numbers
  1. import javax.swing.JOptionPane;am?", "Number of people", JOptionPane.QUESTION_MESSAGE);
  2.  
  3.     numPeople = Integer.parseInt(numberOfPeople);
  4.  
  5.     int count = 0;
  6.     String[] firstName = new String[numPeople];
  7.     String[] lastName = new String[numPeople];
  8.     int[] birthdate = new int[numPeople];
  9.  
  10.  
  11.         if(count <= numPeople)
  12.         {
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.*
Feb 19 '07 #3
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...
Feb 19 '07 #4
r035198x
13,262 8TB
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
Feb 19 '07 #5
hirak1984
316 100+
May I ask you what have you extended?

JApplet or JFrame?

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...
Feb 19 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

19
by: Canonical Latin | last post by:
"Leor Zolman" <leor@bdsoft.com> wrote > "Canonical Latin" <javaplus@hotmail.com> wrote: > > > ... > >But I'm still curious as to the rational of having type >...
21
by: Matteo Settenvini | last post by:
Ok, I'm quite a newbie, so this question may appear silly. I'm using g++ 3.3.x. I had been taught that an array isn't a lot different from a pointer (in fact you can use the pointer arithmetics to...
5
by: JezB | last post by:
What's the easiest way to concatenate arrays ? For example, I want a list of files that match one of 3 search patterns, so I need something like DirectoryInfo ld = new DirectoryInfo(searchDir);...
3
by: Michel Rouzic | last post by:
It's the first time I try using structs, and I'm getting confused with it and can't make it work properly I firstly define the structure by this : typedef struct { char *l1; int *l2; int Nval; }...
1
by: Rob Griffiths | last post by:
Can anyone explain to me the difference between an element type and a component type? In the java literature, arrays are said to have component types, whereas collections from the Collections...
41
by: Rene Nyffenegger | last post by:
Hello everyone. I am not fluent in JavaScript, so I might overlook the obvious. But in all other programming languages that I know and that have associative arrays, or hashes, the elements in...
6
by: Robert Bravery | last post by:
Hi all, Can some one show me how to achieve a cross product of arrays. So that if I had two arrays (could be any number) with three elements in each (once again could be any number) I would get:...
1
by: Doug_J_W | last post by:
I have a Visual Basic (2005) project that contains around twenty embedded text files as resources. The text files contain two columns of real numbers that are separated by tab deliminator, and are...
16
by: mike3 | last post by:
(I'm xposting this to both comp.lang.c++ and comp.os.ms- windows.programmer.win32 since there's Windows material in here as well as questions related to standard C++. Not sure how that'd go over...
29
weaknessforcats
by: weaknessforcats | last post by:
Arrays Revealed Introduction Arrays are the built-in containers of C and C++. This article assumes the reader has some experiece with arrays and array syntax but is not clear on a )exactly how...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.