I'm working on a project where i have 3 different classes creating objects CommissionEmployee, SalariedEmployee and HourlyEmployee. I need to add these to an arraylist in the main class, but not sure where i'm going wrong.
public class Company {
public String companyName;
public SalariedEmployee owner;
public ArrayList<SalariedEmployee> salariedEmployee;
public ArrayList<HourlyEmployee> hourlyEmployee;
public ArrayList<CommissionEmployee> commissionEmployee;
public Company (String companyName, SalariedEmployee owner){
this.companyName = companyName;
this.owner = owner;
}
public void addSalariedEmployee (SalariedEmployee SalariedEmployee){
salariedEmployee.add(SalariedEmployee); **
}
public void addHourlyEmployee (HourlyEmployee HourlyEmployee){
//HourlyEmployee = new HourlyEmployee (name, position, ratePerHour);
hourlyEmployee.add(HourlyEmployee);
}
public void addCommissionEmployee (CommissionEmployee CommissionEmployee){
//CommissionEmployee = new CommissionEmployee (,, ratePerItem);
commissionEmployee.add(CommissionEmployee);
}
** = this is the line where my editor is telling me i'm going wrong. Cheers, any help will be appreciated
you are using class name as parameter name. it should be different case or any other name instead of class name. but it is better to have camel case name.
just example:
You've attempted to name the parameter the same as your class name. A class name is not acceptable as a parameter name. Name the parameter something different. Even something of different case would be good, e.g.:
Because you have two variables with the same name in that line (i.e. salariedEmployee). Here is the fix for you:
Your method parameter is SINGLE OBJECT. You are trying to put a LIST not an object. You have to change your method parameter
When youll changed, here's an example to deal with the iterator objects.
Remember that JAVA works with objects and everyting its a object. Regards