Array of objects
-
Good day everyone, I have a problem that I really need someone help. I have an array of objects that is filled from the content of a text file. One line in ther text file contains name,address and employeeID. The problem is that I can not compare the employeeID in the object with a given employeeID. How can I get the value of employeeID out of the the array of objects? Please help.Thanks much in advance Employee[] employeeList = new Employee[100]; employeeList = new Employee[100]; EmpFileReader empfile = new EmpFileReader(); employeeList = empfile.readFile(); //getEmployeeID returns ID if(employeeList[i].getEmployeeID()== employeeID ) System.out.println(employeeList[i]);
eric
-
Good day everyone, I have a problem that I really need someone help. I have an array of objects that is filled from the content of a text file. One line in ther text file contains name,address and employeeID. The problem is that I can not compare the employeeID in the object with a given employeeID. How can I get the value of employeeID out of the the array of objects? Please help.Thanks much in advance Employee[] employeeList = new Employee[100]; employeeList = new Employee[100]; EmpFileReader empfile = new EmpFileReader(); employeeList = empfile.readFile(); //getEmployeeID returns ID if(employeeList[i].getEmployeeID()== employeeID ) System.out.println(employeeList[i]);
eric
First thing you need to do is that you have to ensure whether readFile() method can parse the value from text file to the employee object. Once you are sure about readFile(), you can just loop through the array and compare the ID..
eric_tran wrote:
Employee[] employeeList = new Employee[100]; employeeList = new Employee[100];
No need to instantiate the array twice. btw.
Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)
-
First thing you need to do is that you have to ensure whether readFile() method can parse the value from text file to the employee object. Once you are sure about readFile(), you can just loop through the array and compare the ID..
eric_tran wrote:
Employee[] employeeList = new Employee[100]; employeeList = new Employee[100];
No need to instantiate the array twice. btw.
Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)
Hi Michael, I'm sure that the array of object has all data pulled from the text file. I can get the value of employeeID from the array of object, but when I compare with a given string, then it does not work. for (int i=0; i { if(employeeList[i].getEmployeeID()== "1234" ) System.out.println(employeeList[i]); }
eric
modified on Sunday, December 30, 2007 6:25:21 AM
-
Hi Michael, I'm sure that the array of object has all data pulled from the text file. I can get the value of employeeID from the array of object, but when I compare with a given string, then it does not work. for (int i=0; i { if(employeeList[i].getEmployeeID()== "1234" ) System.out.println(employeeList[i]); }
eric
modified on Sunday, December 30, 2007 6:25:21 AM
Try to write all id of employees array.. see whether you got all employee ids (including the one that you want to search) or not..
For each(Employee emp in Employees){ Console.WriteLine(emp.ID.ToString()); }
Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)