用JAVA语言写一个计算员工月工资的程序

一.任务需求

某公司分为多个部门,每个部门有一个经理和多个员工,每个员工根据职称发基本工资。员工的工资由基本工资,日加班工资,日缺勤工资等组成。具体需求如下所示:

员工的基本信息,包括部门,职务,职称以及工资记录等信息。

能记录员工的每一个职称信息,并授予相应的职称,系统在计算员工工资的时候职称对应的最高职称津贴。

二.问题域中涉及多个类,包括职员类Staff,经理类Manger,测试类TestEmployee.

Staff类:通过此类封装定义计算职员基本工资方法

Manger类:通过此类封装定义计算经理基本工资方法。

TestManger :调用方法并实现结果输出

三.代码展示

Emploee类

package com.daiinfo.seniorjava.ken1.implment;

public class Employee {
	String ID;
    String name;

    int workdays;//工作天数
    int overtimedays;//加班天数
    int absentdays;//缺勤天数
    int salary;//月工资

    /**
     * 构造函数
     */
     public Employee(String ID){
         this.ID =ID;
     }


     /**
      * 构造函数
      */
     public Employee (String ID,String name){
         this.ID=ID;
         this.name=name;
     }


     /**
      * 计算员工工资
      * workdays 工作天数
      * overtimedays 加班天数
      * absentdays 缺勤天数
      * return 返回月总工资
      */
     double calculateCount(int workdays,int overtimedays,int absentdays){
       double count;
       count =80.0*workdays+80*overtimedays-30*absentdays;  
       return count;
     }


     /**
      * 转换字符串
      */
     public String toString(){
         return name +"\t"+salary;
     }
}

Staff类

package com.daiinfo.seniorjava.ken1.implment;

public class Staff extends Employee {
	double bassewages = 2000;
    double dailywages = 50;// 日工资
    String department;
    String technicaltitle;

    /**
     * 构造函数
     */
    public Staff(String ID, String name, String department, String technicaltitle) {
        super(ID, name);
        this.department = department;
        this.technicaltitle = technicaltitle;
    }

    /**
     * 计算员工的工资 wordays 工作天数 overtimedays 加班天数 absencedays 缺勤天数
     * 
     * @return 返回月工资
     */
    double calculateCount(int workdays, int overtimedays, int absencedays) {
        double count = 0.0;
        count = bassewages + dailywages * overtimedays - dailywages * absencedays;
        return count;
    }

    /**
     * 转换字符串输出信息
     */
    public String toString(){
        return name +"\t"+salary;
    }
}

Manager类

package com.daiinfo.seniorjava.ken1.implment;

public class Manager extends Employee{
	double basewages = 3000;
    String department;// 所在部门
    String positions;

    /**
     * 构造函数 ID name department
     */
    public Manager(String ID, String name, String department, String positions) {
        // TODO Auto-generated constructor stub
        super(ID, name);
        this.department = department;
        this.positions = positions;
    }

    /**
     * 计算经理工资 workdays 工作天数 overtimedays 加班天数 absentdaysn 缺勤天数 返回月工资
     */
    double calculateCount(int workdays, int overtimedays, int absencedays) {
        double count = 0.0;
        count = basewages + 20 * overtimedays - 30 * absencedays;
        return count;
    }
}

TestEmployee类

package com.daiinfo.seniorjava.ken1.implment;

public class TestEmployee {
	public static void main(String[] args) {
        Manager manager = new Manager("001", "张三", "开发部", "经理");
        double countsalary = manager.calculateCount(22, 3, 0);
        System.out.println(countsalary);

        Staff staff = new Staff("2001", "王好", "财务部", "会计师");
        double salary = staff.calculateCount(20, 5, 1);
        System.out.println(salary);
    }

}

  • 7
    点赞
  • 69
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值