1、 编写Employee类,成员变量:name,age,tel,gz,并为其添加相应的set和get方法, 1个方法:aiseSalary(double proportion):涨工资方法。 2.编写Manager类,该类继承于的Employee类 (1)为其添加: 两个属性:办公室officeID和年终分红bonus; 1构造器方法:带有5个参数的构造器方法,用于对除bonus属性外的所有其它属性进行初始化; 方法:officeID属性和bonus属性的相关set和get方法; (2)重写Employee类中的方法raiseSalary(double proportion),经理涨工资的计算方法为在雇员工资涨幅的基础上增加10%的比例。
3.编写TemporaryEmployee(临时工)类,该类继承于Employee类 (1)为其添加: 1个属性:雇佣年限hireYears; 构造器方法:用于初始化该类的所有属性; 方法:hireYears属性的set和get方法;(2)重写Employee类中的方法raiseSalary(double proportion),临时工的工资涨幅为正式雇员的50%。
public class Employee { //name,age,tel,gz String name; int age; String tel; double gz; public Employee() { } /* * 涨工资方法 * */ public void raiseSalary(double proportion){ this.setGz(this.gz+proportion); } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getTel() { return tel; } public void setTel(String tel) { this.tel = tel; } public double getGz() { return gz; } public void setGz(double gz) { this.gz = gz; } } ------------------------------------------------------------------ public class Manager extends Employee { private String officeID;// 此处不了解你的办公室具体ID生成策略,用String类型 private double bonus; public Manager() { // 实体类的空参数构造方法(java bean) } public Manager(String name, int age, String tel, double gz, String officeID) { this.name = name; this.age = age; this.tel = tel; this.gz = gz; this.officeID = officeID; } /* * 重写涨工资方法 * */ public void raiseSalary(double proportion){ this.setGz(this.gz+proportion*1.1); } public String getOfficeID() { return officeID; } public void setOfficeID(String officeID) { this.officeID = officeID; } public double getBonus() { return bonus; } public void setBonus(double bonus) { this.bonus = bonus; } } ------------------------------------------------------------------- public class TemporaryEmployee extends Employee { private int hireYears; public TemporaryEmployee(){ } public TemporaryEmployee(String name, int age, String tel, double gz,int hireYears){ this.name = name; this.age = age; this.tel = tel; this.gz = gz; this.hireYears = hireYears; } /* * 重写涨工资方法 * */ public void raiseSalary(double proportion) { this.setGz(this.gz+proportion*0.5); } public int getHireYears() { return hireYears; } public void setHireYears(int hireYears) { this.hireYears = hireYears; } }