/*
练习:
假如我们开发一个系统时
需要对员工进行建模 员工包含3个属性 姓名 工号 工资 功能 work
经理 也是员工 除了含有员工的属性外 另外还有一个奖金属性
请用继承的思想设计出 员工类 和 经理类 要求类中提供必要的方法进行属性访问
work 输出内容 是 姓名 工号 工资 有奖金 输出奖金 没奖金 就不输出奖金
分析:
经理是员工 但 经理和普通员工 工作不同 并且多了个奖金
练习:
假如我们开发一个系统时
需要对员工进行建模 员工包含3个属性 姓名 工号 工资 功能 work
经理 也是员工 除了含有员工的属性外 另外还有一个奖金属性
请用继承的思想设计出 员工类 和 经理类 要求类中提供必要的方法进行属性访问
work 输出内容 是 姓名 工号 工资 有奖金 输出奖金 没奖金 就不输出奖金
分析:
经理是员工 但 经理和普通员工 工作不同 并且多了个奖金
*/
package Day10;
public class Test_03 {
public static void main(String[] args) {
//员工类:工号\职位\姓名\工资
//经理级:奖金 (奖金和加班费分别用set和get是因为输错,所以单独输入)
//后勤:加班费
Manager s1 = new Manager("0001","总经理","张华",5000);
s1.setBonus(500);//经理级奖金
s1.work();
Manager s2 = new Manager("0002","副经理","李小",4500);
s2.setBonus(350);//经理级奖金
s2.work();
GeneralStaff s3 =new GeneralStaff("1000","后勤主管","叶斯",3300);
s3.setOverTimePay(1000);//加班费
s3.work();
GeneralStaff s4 =new GeneralStaff("1001","后勤员工","雷五",2800);
s4.setOverTimePay(1000);//加班费
s4.work();
}
}
class Manager extends Staff {//经理级
public Manager(String id, String position, String name, double salary) {
super(id, position, name, salary);
}
private double bonus;// 奖金
public void setBonus(double bonus) {
this.bonus = bonus;
}
public void work() {
super.work();
System.out.println(";奖金:"+ bonus);
}
}
class GeneralStaff extends Staff {// 普通员工类
public GeneralStaff(String id, String position, String name, double salary) {
super(id, position, name, salary);
// TODO Auto-generated constructor stub
}
private double overtimepay;// 加班费
public void setOverTimePay(double overtimepay) {
this.overtimepay = overtimepay;
}
public void work() {
super.work();
System.out.println(";加班费:"+overtimepay);
}
}
class Staff {// 员工类
private String id;// 工号
private String position;// 职位
private String name;// 姓名
private double salary;// 工资
public Staff(String id, String position, String name, double salary) {
super();
this.id = id;
this.position = position;
this.name = name;
this.salary = salary;
}
public void work() {
System.out.print("工号:" + id + ";职位:" + position + ";姓名:" + name + ";工资:" + salary);
}
}