要求定义父类Employee为抽象类,showMessage为抽象方法。增加一个子类DevelopManager扩充了:奖金prize和加班时间overtime两个属性。测试类main方法中,在创建SaleManager对象和DevelopManager对象后,通过定义Employee引用SaleManager对象和DevelopManager对象,分别调用showMessage方法输出: 销售经理信息: 员工信息:姓名:张三;id号:10001;薪金:10000元; 扩展信息:销售收入:1000000元,销售利润:100000元。 开发经理信息: 员工信息:姓名:李四;id号:20001;薪金:20000元; 扩展信息:奖金:1000元,加班时间:10小时。
时间: 2024-02-26 18:58:04 浏览: 72
好的,根据您的要求,我来为您写出相应代码:
```
abstract class Employee {
protected String name;
protected String id;
protected double salary;
public Employee(String name, String id, double salary) {
this.name = name;
this.id = id;
this.salary = salary;
}
public abstract void showMessage();
}
class SaleManager extends Employee {
private double salesIncome;
private double salesProfit;
public SaleManager(String name, String id, double salary, double salesIncome, double salesProfit) {
super(name, id, salary);
this.salesIncome = salesIncome;
this.salesProfit = salesProfit;
}
public void showMessage() {
System.out.println("销售经理信息:");
System.out.println("员工信息:姓名:" + name + ";id号:" + id + ";薪金:" + salary + "元;");
System.out.println("扩展信息:销售收入:" + salesIncome + "元,销售利润:" + salesProfit + "元。");
}
}
class DevelopManager extends Employee {
private double prize;
private double overtime;
public DevelopManager(String name, String id, double salary, double prize, double overtime) {
super(name, id, salary);
this.prize = prize;
this.overtime = overtime;
}
public void showMessage() {
System.out.println("开发经理信息:");
System.out.println("员工信息:姓名:" + name + ";id号:" + id + ";薪金:" + salary + "元;");
System.out.println("扩展信息:奖金:" + prize + "元,加班时间:" + overtime + "小时。");
}
}
public class Test {
public static void main(String[] args) {
SaleManager s = new SaleManager("张三", "10001", 10000, 1000000, 100000);
DevelopManager d = new DevelopManager("李四", "20001", 20000, 1000, 10);
Employee e1 = s;
Employee e2 = d;
e1.showMessage();
e2.showMessage();
}
}
```
希望能对您有所帮助!
阅读全文