添加的问题从不同的类的对象变成一个ArrayList

添加的问题从不同的类的对象变成一个ArrayList

本文介绍了添加的问题从不同的类的对象变成一个ArrayList - java的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个项目在那里我有3个不同的类中创建对象CommissionEmployee,SalariedEmployee和HourlyEmployee。我需要这些主类添加到一个ArrayList,但不知道我要去哪里错了。

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 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);
}

** =这是在我的编辑告诉我,我会错行了。
欢呼声中,任何帮助将AP preciated

** = this is the line where my editor is telling me i'm going wrong.Cheers, any help will be appreciated

推荐答案

由于您有在该行(即salariedEmployee)同名的两个变量。这是给你的修补程序:

Because you have two variables with the same name in that line (i.e. salariedEmployee). Here is the fix for you:

public void addSalariedEmployee (SalariedEmployee aSalariedEmployee){
    salariedEmployee.add(aSalariedEmployee);
}

这篇关于添加的问题从不同的类的对象变成一个ArrayList - java的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 03:02