Hi there! I did have a.toString() method, but I found that I needed the original.toString() method from Arrays.toString(), so I ended up just calling my .tostring() method printerstring.
For some reason when i called Arrays.toString() while my Employee.toString() method existed, it produced a different result, like I had somehow edited Arrays.toString() by creating Employee.toString(). I changed my Employee.toString() method to Employee.printerString();
-EDIT-
typos
-EDIT 2-
I ended up just messing around with my loadEmployees() method and my Employee.create method, cleaned it up and it ended up working. Here is the (semi-)finished code:
import java.util.*;
import java.io.*;
@SuppressWarnings("unchecked")
public class MyClass
{
public static void main (String [] args)
{
ArrayList<Employee> list = loadEmployees();
for (int i=0;i<list.size();i++)
{
System.out.println(list.get(i).printerString());
}
}
public static void processEmployees()
{
ArrayList<Employee> employees = loadEmployees();
printEmployees(employees);
}
@SuppressWarnings("unchecked")
static ArrayList loadEmployees()
{
ArrayList<String> list = new ArrayList<String>();
ArrayList<Employee> employees = new ArrayList<Employee>();
BufferedReader br = null;
String [] strArr, arr = new String[5];
String line;
int count = 0;
try
{
br = new BufferedReader(new FileReader("MyFilePath"));
strArr = new String[10];
while ((line = br.readLine()) != null)
{
strArr = line.split("\\s+");
employees.add(0, Employee.create(strArr)); //just added this part in, rather than that messy forloop
count++;
}
}
catch(Exception e){ System.out.println(e.getMessage()); }
return employees;
}
}
class Employee
{
String name, company, projectName, projectPosition;
private Employee(String name, String company, String projectName, String projectPosition)
{
this.name = name;
this.company = company;
this.projectName = projectName;
this.projectPosition = projectPosition;
}
public String printerString()
{
String str = "Name: " + name + "\nCompany: " + company + "\nProject Name: " + projectName + "\nProject Position: " + projectPosition + "\n";
return str;
}
public static Employee create(String[] str) //changed this method
{
return new Employee(str[1], str[2], str[3], str[4]);
}
}