、(1)创建一个抽象类Worker: 属性:工龄、工号、姓名、基本工资 方法:构造函数;输出所有信息的方法show( 抽象方法Q计算工资SetPay (2)创建一个部门经理类,继承Worker类: 属性:岗位级别,实际工资 方法:构造函数;重写show(),输出所有信息;实现SetPay ,计算工资的方法(实际工资=基本工资+岗位级别*500+工龄*1000) (3)创建一个销售人员类,继承Worker类: 属性:销售金额,实际工资 方法:构造方法;重写show ,输出所有信息;实现SetPay 计算工资的方法(实际工资=基本工资+销售金额*系数(其中系数当销售金额大于100W时为0.09,小于100W时为0.08) (4)创建测试类,分别定义部门经理类和销售人员类对象,计算其工资,并输出信息。
时间: 2024-03-25 13:39:51 浏览: 208
worker-function:创建在Web Worker内部执行的函数并返回Promise
以下是Java代码实现:
Worker类:
```java
public abstract class Worker {
private String name;
private String workerId;
private int seniority;
private double basicSalary;
public Worker(String name, String workerId, int seniority, double basicSalary) {
this.name = name;
this.workerId = workerId;
this.seniority = seniority;
this.basicSalary = basicSalary;
}
public abstract void show();
public abstract void setPay();
// getters and setters
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getWorkerId() {
return workerId;
}
public void setWorkerId(String workerId) {
this.workerId = workerId;
}
public int getSeniority() {
return seniority;
}
public void setSeniority(int seniority) {
this.seniority = seniority;
}
public double getBasicSalary() {
return basicSalary;
}
public void setBasicSalary(double basicSalary) {
this.basicSalary = basicSalary;
}
}
```
Manager类:
```java
public class Manager extends Worker {
private int level;
private double actualSalary;
public Manager(String name, String workerId, int seniority, double basicSalary, int level) {
super(name, workerId, seniority, basicSalary);
this.level = level;
}
@Override
public void show() {
System.out.println("姓名:" + getName());
System.out.println("工号:" + getWorkerId());
System.out.println("基本工资:" + getBasicSalary());
System.out.println("工龄:" + getSeniority());
System.out.println("岗位级别:" + level);
System.out.println("实际工资:" + actualSalary);
}
@Override
public void setPay() {
actualSalary = getBasicSalary() + level * 500 + getSeniority() * 1000;
}
}
```
Salesman类:
```java
public class Salesman extends Worker {
private double salesAmount;
private double actualSalary;
public Salesman(String name, String workerId, int seniority, double basicSalary, double salesAmount) {
super(name, workerId, seniority, basicSalary);
this.salesAmount = salesAmount;
}
@Override
public void show() {
System.out.println("姓名:" + getName());
System.out.println("工号:" + getWorkerId());
System.out.println("基本工资:" + getBasicSalary());
System.out.println("工龄:" + getSeniority());
System.out.println("销售金额:" + salesAmount);
System.out.println("实际工资:" + actualSalary);
}
@Override
public void setPay() {
double coefficient = salesAmount > 1000000 ? 0.09 : 0.08;
actualSalary = getBasicSalary() + salesAmount * coefficient;
}
}
```
Test类:
```java
public class Test {
public static void main(String[] args) {
Manager manager = new Manager("张三", "M001", 5, 10000, 2);
manager.setPay();
manager.show();
Salesman salesman = new Salesman("李四", "S001", 3, 5000, 1200000);
salesman.setPay();
salesman.show();
}
}
```
运行结果:
```
姓名:张三
工号:M001
基本工资:10000.0
工龄:5
岗位级别:2
实际工资:17000.0
姓名:李四
工号:S001
基本工资:5000.0
工龄:3
销售金额:1200000.0
实际工资:113000.0
```
阅读全文