父类:员工类
子类:部门经理类、普通员工类
(1)部门经理工资=1000+单日工资*天数*等级(1.2)。=>奖金
+基本工资
(2)普通员工工资=单日工资*天数*等级(1.0) ;
(3)员工属性:姓名,单日工资,工作天数
(4)员工方法(打印工资)
(5)普遍员工及部门经理都是员工子类,需要重写打印工资方法。
(5)定义并初始化普通员工对象,调用打印工资方法输入工资,定义并初始化部门经理对象,调用打印工资方法输入工资
public class homework04 {
public static void main(String[] args) {
Manager manage = new Manager("刘备", 100, 20, 1.2);
//设置奖金
manage.setBonus(3000);
//打印经理的工资
manage.printSal();
Worker worker = new Worker("关羽", 100, 20, 1.0);
worker.printSal();
}
}
public class employee {
//属性
//员工属性:姓名,单日工资,工作天数
private String name;
private double daySal;
private int workDays;
//分析还有一个等级
private double grade;
//方法[构造器,getter和setter]
public employee(String name, double daySal, int workDays, double grade) {
this.name = name;
this.daySal = daySal;
this.workDays = workDays;
this.grade = grade;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getDaySal() {
return daySal;
}
public void setDaySal(double daySal) {
this.daySal = daySal;
}
public int getWorkDays() {
return workDays;
}
public void setWorkDays(int workDays) {
this.workDays = workDays;
}
public double getGrade() {
return grade;
}
public void setGrade(double grade) {
this.grade = grade;
}
//打印工资方法
//方法void printSal(){}
public void printSal(){
System.out.println(name +"工资=" + daySal * workDays * grade);
}
}
public class Worker extends employee {
public Worker(String name, double daySal, int workDays, double grade) {
super(name, daySal, workDays, grade);
}
@Override
public void printSal() {
super.printSal();
}
}
public class Worker extends Employee{
//分析普通员工没有特有的属性
public Worker(String name, double daySal, int workDays, double grade) {
super(name, daySal, workDays, grade);
}
//重写printSal
//因为普通员工和Employee输出工资情况一下,所以直接调用父类的printSal()
@Override
public void printSal() {
System.out.print("普通员工 ");//自己的输出信息
super.printSal();//调用父类的方法,复用代码
}
}