【java】従業員の給与計算

【事例紹介】

  1. ミッションの詳細

会社には複数の部署があり、従業員情報には名前、職種、部署、基本給などが含まれます。

基本的な給与には、管理者、営業担当者、従業員の 3 つのタイプの従業員があります。

会社の財務部門のスタッフは、毎月の従業員の実際の賃金を計算する必要があります。

実際の給与 = 月収 – 支払うべき個人所得税。

で:

(1) 月収の計算方法は、次の種類に応じて決定されます。

 管理者:月収=基本給+賞与

 営業マン:月収=基本給+営業売上金額×歩合率

 労働者:月収=基本給+残業代残業代支給

(2) 個人所得税の納税方法は統一されており、月収に応じて所得税の控除率が異なります。

 月収⩽5,000元、所得税0元。

 5000<月収⩽15000、所得税:月収×5%。

 15,000<月収、所得税:月収×20%。


抽象クラス Employee、管理者クラス Admin、販売員クラス Salesman、worker クラスの 5 つのクラスを作成し、テスト用のデモ クラス SalayDemo を作成する必要があります。

これらのクラスを cn.edu.gpnu.company パッケージに配置する必要があります。

【事件の目的】

 「従業員の賃金を計算する」という業務を実現するための論理的な考え方を分析する方法を学びます。

 「従業員の給与計算」プログラムのソースコード作成、コンパイル、操作を独力で完了できる。

 Javaにおける継承の知識をマスターする。

 抽象クラスと抽象メソッドの書き方と使い方をマスターする。

【実行結果】
ここに画像の説明を挿入します
【実行コード】
1.

package cn.edu.gpnu.bank.company;

class Admin extends Employee {
    
    
    double bonus;

    public Admin(String name, String type, String department, double basicSalary, double bonus) {
    
    
        super(name, type, department, basicSalary);
        this.bonus = bonus;
    }

    public double getBonus() {
    
    
        return bonus;
    }

    public void setBonus(double bonus) {
    
    
        this.bonus = bonus;
    }

    public double getIncome(){
    
    
        return (getBasicSalary()+getBonus());
    }
}

package cn.edu.gpnu.bank.company;

abstract public class Employee {
    
    
    String name;
    String type;
    String department;
    double basicSalary;

    public Employee(String name, String type, String department, double basicSalary) {
    
    
        this.name = name;
        this.type = type;
        this.department = department;
        this.basicSalary = basicSalary;
    }

    public String getName() {
    
    
        return name;
    }

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

    public String getType() {
    
    
        return type;
    }

    public void setType(String type) {
    
    
        this.type = type;
    }

    public String getDepartment() {
    
    
        return department;
    }

    public void setDepartment(String department) {
    
    
        this.department = department;
    }

    public double getBasicSalary() {
    
    
        return basicSalary;
    }

    public void setBasicSalary(double basicSalary) {
    
    
        this.basicSalary = basicSalary;
    }

    abstract public double getIncome();

    public double getTax(){
    
    
        double income = getIncome();
        if(income<=5000)
        {
    
    
            return 0;
        }
        if(income>5000 && income<=15000)
        {
    
    
            return income*0.05;
        }
        else
        {
    
    
            return income * 0.2;
        }
    }

    public String info(){
    
    
        return"姓名:"+this.name+",类型:"+this.type+",部门:"+this.department
                +",月收入:"+getIncome()+"元,所得税:"+getTax()+"元,实发工资:"
                +(getIncome()-getTax())+"元";

    }


}

package cn.edu.gpnu.bank.company;

class Salesman extends Employee {
    
    
    double saleAmount;
    double rate;

    public Salesman(String name, String type, String department, double basicSalary, double saleAmount, double rate) {
    
    
        super(name, type, department, basicSalary);
        this.saleAmount = saleAmount;
        this.rate = rate;
    }

    public double getSaleAmount() {
    
    
        return saleAmount;
    }

    public void setSaleAmount(double saleAmount) {
    
    
        this.saleAmount = saleAmount;
    }

    public double getRate() {
    
    
        return rate;
    }

    public void setRate(double rate) {
    
    
        this.rate = rate;
    }

    public double getIncome() {
    
    
        return (getBasicSalary()+getSaleAmount()*getRate());
    }
}

package cn.edu.gpnu.bank.company;

class Worker extends Employee {
    
    
    double overtimePay;

    public Worker(String name, String type, String department, double basicSalary, double overtimePay) {
    
    
        super(name, type, department, basicSalary);
        this.overtimePay = overtimePay;
    }

    public double getOvertimePay() {
    
    
        return overtimePay;
    }

    public void setOvertimePay(double overtimePay) {
    
    
        this.overtimePay = overtimePay;
    }

    public double getIncome() {
    
    
        return (getBasicSalary()+getOvertimePay());
    }
}

package cn.edu.gpnu.bank.company;

public class SalayDemo {
    
    
    public static void main(String[] args) {
    
    
        Admin admin = new Admin("张三", "管理员",
                "研发部", 14000, 5600);

        Salesman salesman = new Salesman("李四", "销售员",
                "天河销售部", 6000, 98900, 0.03);

        Worker worker = new Worker("王五", "工人",
                "南沙制造场", 2500, 1350);

        System.out.println(admin.info());
        System.out.println(salesman.info());
        System.out.println(worker.info());

    }
}

おすすめ

転載: blog.csdn.net/m0_52703008/article/details/126200732