PDA

Click to See Complete Forum and Search --> : Multidimensional Array?


rockies1
Jun 23rd, 2003, 07:48 AM
How do I use a multidimensional array?

I will have an unknown number of records with 10 fields apiece.

Is an array the way to go or is there a better way?

Thanks!

Dillinger4
Jun 23rd, 2003, 01:13 PM
I would think that an array would be enough rather than use a multidimensional array.

public class Y{
public static void main(String[] args){
X x = new X();
x.findRecord("Bill Murray");
}
}
class X{
private Employee[] emp;

public X(){
emp = new Employee[] {new Employee(165,"Craig Johnson"), new Employee(182,"Bill Murray")};
}
public void findRecord(String persontofind){
for(int i = 0; i < emp.length; ++i){
if(emp[i].getEmpName().equals(persontofind)){
System.out.print(emp[i].getEmpId() + "\t");
System.out.print(emp[i].getEmpName());
break;
}else{
if(i == emp.length - 1){
System.out.println("Employee could not be found");
}
}
}
}
}

class Employee{
private int empid;
private String name;

public Employee(int empid, String name){
this.empid = empid;
this.name = name;
}

public int getEmpId(){return empid;}
public String getEmpName(){return name;}
}