- #1
stripes
- 266
- 0
Homework Statement
Very simple problem; I have three classes, Company, CompanyTest, and Employee. CompanyTest gets a bunch of information together about an employee, like salary, address, etc., and then it creates an Employee object using the Employee class. Great, so I have successfully asked the user for information, and an Employee object, let's call it emp, has been created.
Now in Company class, I have an ArrayList (obviously dynamic) that will keep a list of all the employees. In Company, I also have the following method:
Code:
public ArrayList<Employee> list = new ArrayList<Employee>();
public void addEmployee(Employee person)
{
list.add(person);
}
Finally, in CompanyTest, I want to add this object emp by saying
Code:
Company.addEmployee(emp);
in CompanyTest. So I'm trying to add emp to the list of employees, and each Employee object will be created in Employee class.
I keep getting the error:
Code:
CompanyTest.java:49: non-static method addEmployee(Employee) cannot be referenced from a static context
Company.addEmployee(emp);
^
1 error
So my question is: how do I add an employee to this list that is created in Company class? This is getting very annoying as it is a very simple task that a computer can't seem to get.
Thanks in advance.