I figured most of it out but I need help with one thing -
In main I have
Code
EmployeeDataReader employeeDataReader = new EmployeeDataReader("EmployeeData/EmployeeData.csv");
Employee[] employeeDatabase = employeeDataReader.getEmployeeData();
displayEmployees(employeeDatabase);
And in EmployeeDataReader I have:
Code
public Employee[] getEmployeeData(){
getFilePath();
/*Reads from the file stored in the attribute filePath. The file used is stored in
EmployeeData/EmployeeData.csv. A “csv” is a file structure that uses commas to
delimited values, thus the meaning comma separated values (csv). After you read a line
from the file use the split(“,”) string method, that will decompose the line into an array of
strings. Next you need to create a new Employee Object with the contents from the array of
strings returned from split and store that into an array of Employee Objects. An initialized
array of Employees will be returned to the caller.
The EmployeeData.csv file structure is: name,age,salary
Note: Check for overflow of your array, never trust that the number of lines in a file will be
the same size as your array! Make sure you use the int Integer.parseInt(String s) and
*/
try {
BufferedReader data = new BufferedReader(new FileReader(filePath));
while ((filePath = data.readLine()) != null) {
// use comma as separator
String[] dataz = line.split(",");
String name = dataz[0];
int age = Integer.parseInt(dataz[1]);
double salary = Double.parseDouble(dataz[2]);
}
return;
}
How do I create an object like this:
Next you need to create a new Employee Object with the contents from the array of strings returned from split and store that into an array of Employee Objects. An initialized array of Employees will be returned to the caller.
The EmployeeData.csv file structure is: name,age,salary
Just Employee = new Employee(name, age, salary); ??
This post was edited by HoneyBadger on Sep 15 2014 02:24pm