输出一组公司员工的信息列表,其中员工具备以下特征: 雇员:员工编号、姓名、工资; 经理:员工编号、姓名、工资、管理部门; 总监:员工编号、姓名、工资、津贴;
时间: 2023-11-04 13:06:50 浏览: 41
员工信息列表如下:
| 员工编号 | 姓名 | 工资 | 管理部门/津贴 |
| -------- | ---- | ---- | -------------- |
| 001 | 张三 | 5000 | |
| 002 | 李四 | 6000 | 销售部 |
| 003 | 王五 | 7000 | |
| 004 | 赵六 | 8000 | 500 |
| 005 | 钱七 | 9000 | 800 |
其中,001号员工为普通员工,没有管理部门也没有津贴;002号员工为经理,管理销售部,没有津贴;003号员工为普通员工,没有管理部门也没有津贴;004号员工为总监,没有管理部门,但有500元的津贴;005号员工为总监,没有管理部门,但有800元的津贴。
相关问题
java输出一组公司员工的信息列表,其中员工具备以下特征: 雇员:员工编号、姓名、工资; 经理:员工编号、姓名、工资、管理部门; 总监:员工编号、姓名、工资、津贴;
以下是Java代码示例:
```
public class Employee {
private int empId;
private String name;
private double salary;
public Employee(int empId, String name, double salary) {
this.empId = empId;
this.name = name;
this.salary = salary;
}
public int getEmpId() {
return empId;
}
public void setEmpId(int empId) {
this.empId = empId;
}
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;
}
@Override
public String toString() {
return "Employee{" +
"empId=" + empId +
", name='" + name + '\'' +
", salary=" + salary +
'}';
}
}
public class Manager extends Employee {
private String department;
public Manager(int empId, String name, double salary, String department) {
super(empId, name, salary);
this.department = department;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
@Override
public String toString() {
return "Manager{" +
"empId=" + getEmpId() +
", name='" + getName() + '\'' +
", salary=" + getSalary() +
", department='" + department + '\'' +
'}';
}
}
public class Director extends Employee {
private double allowance;
public Director(int empId, String name, double salary, double allowance) {
super(empId, name, salary);
this.allowance = allowance;
}
public double getAllowance() {
return allowance;
}
public void setAllowance(double allowance) {
this.allowance = allowance;
}
@Override
public String toString() {
return "Director{" +
"empId=" + getEmpId() +
", name='" + getName() + '\'' +
", salary=" + getSalary() +
", allowance=" + allowance +
'}';
}
}
public class EmployeeList {
public static void main(String[] args) {
Employee e1 = new Employee(1001, "John Smith", 35000);
Manager m1 = new Manager(1002, "Jane Doe", 45000, "Sales");
Director d1 = new Director(1003, "Mike Johnson", 80000, 15000);
System.out.println(e1);
System.out.println(m1);
System.out.println(d1);
}
}
```
在上面的示例中,我们定义了三个类:Employee、Manager和Director,并在EmployeeList类中创建了一个员工信息列表。我们可以看到,每个类都有自己的属性和方法,而Manager和Director类继承了Employee类的属性和方法,并添加了它们自己的属性和方法。我们还重写了每个类的toString()方法,以便在输出时可以打印出正确的信息。
运行EmployeeList类的main方法,得到以下输出:
```
Employee{empId=1001, name='John Smith', salary=35000.0}
Manager{empId=1002, name='Jane Doe', salary=45000.0, department='Sales'}
Director{empId=1003, name='Mike Johnson', salary=80000.0, allowance=15000.0}
```
这表明我们成功地创建了一组公司员工信息列表,并正确地打印出了每个员工的信息。
java实现输出一组公司员工的信息列表,其中员工具备以下特征: 雇员:员工编号、姓名、工资; 经理:员工编号、姓名、工资、管理部门; 总监:员工编号、姓名、工资、津贴;
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();
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)