java实现输出一组公司员工的信息列表,其中员工具备以下特征: 雇员:员工编号、姓名、工资; 经理:员工编号、姓名、工资、管理部门; 总监:员工编号、姓名、工资、津贴;
时间: 2023-10-09 09:08:38 浏览: 89
TP-POO-Employeur:TP POO雇主j,ava
public class Employee {
private int employeeId;
private String name;
private double salary;
public Employee(int employeeId, String name, double salary) {
this.employeeId = employeeId;
this.name = name;
this.salary = salary;
}
public int getEmployeeId() {
return employeeId;
}
public void setEmployeeId(int employeeId) {
this.employeeId = employeeId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public String toString() {
return "Employee ID: " + employeeId + ", Name: " + name + ", Salary: " + salary;
}
}
public class Manager extends Employee {
private String department;
public Manager(int employeeId, String name, double salary, String department) {
super(employeeId, name, salary);
this.department = department;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public String toString() {
return super.toString() + ", Department: " + department;
}
}
public class Director extends Employee {
private double allowance;
public Director(int employeeId, String name, double salary, double allowance) {
super(employeeId, name, salary);
this.allowance = allowance;
}
public double getAllowance() {
return allowance;
}
public void setAllowance(double allowance) {
this.allowance = allowance;
}
public String toString() {
return super.toString() + ", Allowance: " + allowance;
}
}
public class EmployeeList {
private ArrayList<Employee> employees;
public EmployeeList() {
employees = new ArrayList<Employee>();
}
public void addEmployee(Employee e) {
employees.add(e);
}
public void displayEmployees() {
for (Employee e : employees) {
System.out.println(e.toString());
}
}
}
// Example usage
EmployeeList employeeList = new EmployeeList();
employeeList.addEmployee(new Employee(1, "John Doe", 50000));
employeeList.addEmployee(new Manager(2, "Jane Smith", 60000, "Sales"));
employeeList.addEmployee(new Director(3, "Bob Johnson", 70000, 10000));
employeeList.displayEmployees();
阅读全文