# Help with table array

I don't know how to get started on this.  The problem is this:

Make a table.  Each column represents a 1D array.  We have 3 arrays (Name[7], Age[7], and Salary[7].) The first location from the first array is related to the first location from the second array and related to the first location from the third array.  Write a program to input values, then display the info for people who are over 30 years old.  To  display name, age and salary.  Any suggestions on how to start???
Asked:
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
i think it means this

name   age   salary
name   age   salary
name   age   salary
name   age   salary
name   age   salary
name   age   salary
name   age   salary

so creating a mult demensional array

int[][] mytable = new int[3][7];
for (int i = 0; i < inputArraySize.length;i++)//i.e for the input arrays
{
mytable[0][i]  = nameArray[i];
mytable[1][i]  = ageArray[i];
mytable[2][i]  = salaryArray[i];
}

that will dot he insert

then to get all people over 30

for(int i = 0; i < myarray[1].length;i++)
{
if(myarray[1][i] > 30)
System.out.println("Name: " + myarray[0][i] + " Age: " + myarray[2][i]);
}

think this is what ya want??

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
Your code will be more readable if you use named constants rather than integer literals as indices:

private static final int NAME = 0;
private static final int AGE = 1;
private static final int SALARY = 2;

....

mytable[NAME][i]  = nameArray[i];
mytable[AGE][i]  = ageArray[i];
mytable[SALARY][i]  = salaryArray[i];

...

if(myarray[AGE][i] > 30)
Author Commented:
How do I add multiple values:

Such as:
Melissa 35  \$28500
Pat 53  \$75000
Jane  49  \$38000
Commented:
depends are you going to be adding them dynamically?
If so it might be a better idea to create some form of list? Maybe linkedlist and have objects that have name age and salary
ie.

public class person
{
int age;
int salary;
String name;
public person( String name, int age, int salary)
{
this.name = name;
this.age = age;
this.salary = salary;
}

public int getSalary()
{
return salary;
}

public void setSalary(int sal)
{
salary = sal;
}
//do same for other variables
}

then create a linked list in your code with objects like that
LinkedList myList = new LinkedList();
//to add a person
myList.add(new person("Melissa ",35,28500))

//to search for people over 30

for(int i = 0; i < mylist.size();i++)
{
Person currentPerson = (Person)myList.get(i);
if(currentPerson.getAge() > 30)
System.out.println(currentPerson.getName() + " is over 30");
}

a nicer way to do it if you have to add people

if u need to add to the array where position you want is the index in the array to insert the new person

mytable[NAME][position you want]  = “Melissa”;
mytable[AGE][ position you want]  = 53  ;
mytable[SALARY] [position you want]  = 28500;

just a note you probably want to use a string array because int[] wont work for the names :)
Commented:
sorry just make sure the class name starts with a captail hehe typo in my previous quote i.e person = Person
Author Commented:
Thanks!  :)

###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.