JDBC 员工工资管理系统 请各位解答

重构工资计算方法

问题遇到的现象和发生背景

员工工资管理系统
Employee:这是所有员工总的父类,属性:员工编号、姓名、出生日期。方法:getSalary(int month)根据参数月份来计算某月工资,如果该月员工过生日,则公司会额外奖励200元。
SalesEmployee:Employee的子类,销售人员,工资由底薪和月销售额和提成率决定。属性:底薪,月销售额,提成率。
ManagerEmployee:Employee的子类,管理人员,工资由基础工资、岗位工资和绩效工资决定。属性:基础工资,岗位工资,绩效系数。绩效基数是所有销售人员销售提成平均值的60%。
OfficeEmployee:Employee的子类,内勤员工,工资由基础工资、岗位工资决定。属性:基础工资,岗位工资。

问题相关代码,请勿粘贴截图
import java.util.Date;

/**
 * Employee:这是所有员工总的父类。
 * 属性:员工的姓名,员工的生日月份。
 * 方法:getSalary(int month)根据参数月份来确定工资,如果该月员工过生日,则公司会额外奖励100元。
 */
public class Employee {
    private String id;  //员工编号
    private String name;//姓名
    private String date;//出生日期

    public Employee() {
        super();
    }

    public Employee(String id, String name, String date) {
        super();
        this.id = id;
        this.name = name;
        this.date = date;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public double getSalary(int month){
        Date date = new Date();
        int m =date.getMonth() + 1;
        if (month == m) {
            return 200;
        } else {
            return 0;
        }
    }
}
/**
 * SalesEmployee:Employee的子类,销售人员,工资由底薪和月销售额和提成率决定。
 * 属性:底薪,月销售额,提成率。
 */
public class SalesEmployee extends Employee {
    private int dx;     //底薪
    private int yxse;   //月销售额
    private int tcl;    //提成率

    public SalesEmployee(int dx, int xxse, int tcl) {
        this.dx = dx;
        this.yxse = xxse;
        this.tcl = tcl;
    }

    public SalesEmployee(String id, String name, String date, int dx, int yxse, int tcl) {
        super(id, name, date);
        this.dx = dx;
        this.yxse = yxse;
        this.tcl = tcl;
    }

    public int getDx() {
        return dx;
    }

    public void setDx(int dx) {
        this.dx = dx;
    }

    public int getXxse() {
        return yxse;
    }

    public void setXxse(int yxse) {
        this.yxse = yxse;
    }

    public int getTcl() {
        return tcl;
    }

    public void setTcl(int tcl) {
        this.tcl = tcl;
    }

    // 计算工资方法重载
    public double getSalary(int month) {
        return dx + yxse * tcl + super.getSalary(month);
    }
}
/**
 * ManagerEmployee:Employee的子类,管理人员,工资由基础工资、岗位工资和绩效工资决定。
 * 属性:基础工资,岗位工资,绩效系数。
 * 绩效基数是所有销售人员销售提成平均值的60%。
 */
public class ManagerEmployee extends Employee {
    private int jcgz;       //基础工资
    private int gwgz;       //岗位工资
    private double jxxs;    //绩效系数

    public ManagerEmployee(int jcgz, int gwgz, int jxxs) {
        this.jcgz = jcgz;
        this.gwgz = gwgz;
        this.jxxs = jxxs;
    }

    public ManagerEmployee(String id, String name, String date, int jcgz, int gwgz, double jxxs) {
        super(id, name, date);
        this.jcgz = jcgz;
        this.gwgz = gwgz;
        this.jxxs = jxxs;
    }

    public int getJcgz() {
        return jcgz;
    }

    public void setJcgz(int jcgz) {
        this.jcgz = jcgz;
    }

    public int getGwgz() {
        return gwgz;
    }

    public void setGwgz(int gwgz) {
        this.gwgz = gwgz;
    }

    public double getJxxs() {
        return jxxs;
    }

    public void setJxxs(double jxxs) {
        this.jxxs = jxxs;
    }

    // 计算工资方法重载
    public double getSalary(int month) {
        //绩效工资=绩效基数*绩效系数
        //绩效基数=所以销售人员的销售提成的平均值*60%
        //销售提成=月销售额*提成率
        return jcgz + gwgz+  super.getSalary(month);
    }
}
我的解答思路和尝试过的方法

//绩效工资=绩效基数绩效系数
//绩效基数=所以销售人员的销售提成的平均值
60%
//销售提成=月销售额*提成率

我想要达到的结果

为 ManagerEmployee重构方法 计算出工资

因为不知道怎么把总销售提成传入进去,所以我在ManagerEmployee类增加了一个字段salarys用于存储总销售提成,然后把此月生日判断稍微修改了一下,增加了OfficeEmployee内勤员工类的实现,给每个类增加toString()方法用于打印对象的信息,修改如下:

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
 
/**
 * Employee:这是所有员工总的父类。
 * 属性:员工的姓名,员工的生日月份。
 * 方法:getSalary(int month)根据参数月份来确定工资,如果该月员工过生日,则公司会额外奖励100元。
 */
public class Employee {
    private String id;  //员工编号
    private String name;//姓名
    private String date;//出生日期
 
    public Employee() {
        super();
    }
 
    public static void main(String[] args) {
        
        SalesEmployee se1 = new SalesEmployee("B000","张三","2001-06-11",3000, 90000, 0.3);
        //System.out.println(se1.getDate());
        System.out.println(se1+"\n");
        SalesEmployee se2 = new SalesEmployee("B001","李四","2002-06-12",3000, 190000, 0.25);
        System.out.println(se2+"\n");
        SalesEmployee se3 = new SalesEmployee("B002","王五","2003-06-15",3000, 290000, 0.2);
        System.out.println(se3+"\n");
        
        double allSalasCommission = se1.salesCommission()
                                    +se2.salesCommission()
                                    +se3.salesCommission();
        ManagerEmployee me = new ManagerEmployee("A001","小花","2002-06-11",5000,2000, 0.6,allSalasCommission);
        System.out.println(me+"\n");
        
        OfficeEmploye oe = new OfficeEmploye("C001","小月","2002-06-11",3000, 1000);
        System.out.println(oe);
        
        
    }
    
    public Employee(String id, String name, String date) {
        super();
        this.id = id;
        this.name = name;
        this.date = date;
    }
 
    public String getId() {
        return id;
    }
 
    public void setId(String id) {
        this.id = id;
    }
 
    public String getName() {
        return name;
    }
 
    public void setName(String name) {
        this.name = name;
    }
 
    public String getDate() {
        return date;
    }
 
    public void setDate(String date) {
        this.date = date;
    }
 
   //参考资料:https://www.csdn.net/tags/Mtjakg4sNDcyMTMtYmxvZwO0O0OO0O0O.html
    public double getSalary() throws ParseException{
        Date date = new Date();
        int m =date.getMonth() ;
       // System.out.println(date+",m="+m);
        
        //把生日字符串转为date类型
        SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd"); 
        Date birthday = ft.parse(this.date);  //把月提取出来
        //System.out.println(birthday);  
        if (birthday.getMonth() == m) { //判断是否此月生日
            return 200;
        } else {
            return 0;
        }
    }
}
/**
 * SalesEmployee:Employee的子类,销售人员,工资由底薪和月销售额和提成率决定。
 * 属性:底薪,月销售额,提成率。
 */
class SalesEmployee extends Employee {
    private int dx;     //底薪
    private int yxse;   //月销售额
    private double tcl;    //提成率
 
    public SalesEmployee(int dx, int xxse, double tcl) {
        this.dx = dx;
        this.yxse = xxse;
        this.tcl = tcl;
    }
 
    public SalesEmployee(String id, String name, String date, int dx, int yxse, double tcl) {
        super(id, name, date);
        this.dx = dx;
        this.yxse = yxse;
        this.tcl = tcl;
    }
 
    public int getDx() {
        return dx;
    }
 
    public void setDx(int dx) {
        this.dx = dx;
    }
 
    public int getXxse() {
        return yxse;
    }
 
    public void setXxse(int yxse) {
        this.yxse = yxse;
    }
 
    public double getTcl() {
        return tcl;
    }
 
    public void setTcl(double tcl) {
        this.tcl = tcl;
    }
 
    // 计算工资方法重载
    public double getSalary() throws ParseException {
        return dx + yxse * tcl + super.getSalary();
    }
    
    //销售提成
    public double salesCommission() {
        return this.yxse*this.tcl;
    }

    @Override
    public String toString() {
        double salary=0;
        try {
            salary = getSalary();
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return "SalesEmployee [员工编号:"+getId()+",姓名:"+getName()
                + ",出生日期:"+getDate()
                + ",底薪=" + dx +
                ", 销售额=" + yxse + ", 销售提成率=" + tcl 
                +",销售提成"+salesCommission()
                +",总工资:"+salary+ "]";
    }
    
    
}
/**
 * ManagerEmployee:Employee的子类,管理人员,工资由基础工资、岗位工资和绩效工资决定。
 * 属性:基础工资,岗位工资,绩效系数。
 * 绩效基数是所有销售人员销售提成平均值的60%。
 */
class ManagerEmployee extends Employee {
    private int jcgz;       //基础工资
    private int gwgz;       //岗位工资
    private double jxxs;    //绩效系数
    private double salarys;
 
    public ManagerEmployee(int jcgz, int gwgz, int jxxs) {
        this.jcgz = jcgz;
        this.gwgz = gwgz;
        this.jxxs = jxxs;
    }
 
    public ManagerEmployee(String id, String name, String date, int jcgz, int gwgz, double jxxs,double salarys) {
        super(id, name, date);
        this.jcgz = jcgz;
        this.gwgz = gwgz;
        this.jxxs = jxxs;
        this.salarys = salarys;
    }
 
    public int getJcgz() {
        return jcgz;
    }
 
    public void setJcgz(int jcgz) {
        this.jcgz = jcgz;
    }
 
    public int getGwgz() {
        return gwgz;
    }
 
    public void setGwgz(int gwgz) {
        this.gwgz = gwgz;
    }
 
    public double getJxxs() {
        return jxxs;
    }
 
    public void setJxxs(double jxxs) {
        this.jxxs = jxxs*0.6;
    }
 
    // 计算工资方法重载
    public double getSalary() throws ParseException {
        //绩效工资=绩效基数*绩效系数
        //绩效基数=所以销售人员的销售提成的平均值*60%
        //销售提成=月销售额*提成率
        return jcgz + gwgz+getJxxs()*this.salarys  +super.getSalary();
    }

    @Override
    public String toString() {
        double salary=0;
        try {
            salary = getSalary();
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return "ManagerEmployee [员工编号:"+getId()+",姓名:"+getName()
                + ",出生日期:"+getDate()
                + "基础工资=" + jcgz + ", 岗位工资=" + gwgz + ", 绩效系数=" + jxxs 
                + ",销售总提成:"+this.salarys+",总工资:"+salary+"]";
    }
    
    
}

class OfficeEmploye extends Employee{
    
    double basesalary;
    double postsalary;
    
    public OfficeEmploye (String id, String name, String date, double basesalary ,double postsalary) {
        super(id, name, date);
        this.basesalary = basesalary;
        this.postsalary = postsalary;
    }
    
    public double getBasesalary() {
        return basesalary;
    }
    
    public void setBasesalary(double basesalary) {
        this.basesalary = basesalary;
    }
    
    public double getPostsalary() {
        return postsalary;
    }
    
    public void setPostsalary(double postsalary) {
        this.postsalary = postsalary;
    }
    
    
    // 计算工资方法重载
    public double getSalary() throws ParseException {
       
        return this.basesalary+this.postsalary +super.getSalary();
    }

    @Override
    public String toString() {
        double salary=0;
        try {
            salary = getSalary();
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return "OfficeEmploye [员工编号:"+getId()+",姓名:"+getName()
                + ",出生日期:"+getDate()
                + "基础工资=" + basesalary + ", 岗位工资=" + postsalary 
                +",总工资="+salary+ "]";
    }
    
    
    
    
}


img