【java】Calculate employee salary

【Case introduction】

  1. mission details

A company has multiple departments. The employee information includes name, type, department and basic salary.

basicSalary, there are three types of employees: administrators, salespeople and workers.

The staff of the company's financial department must calculate the actual wages of employees every month.

Actual salary = monthly income – personal income tax payable.

in:

(1) The monthly income calculation method is determined based on the type:

 Administrator: monthly income = basic salary + bonus

 Salesperson: monthly income = basic salary + sales salesAmount * commission rate rate

 Workers: monthly income = basic salary + overtime pay overtimePay

(2) The method of paying personal income tax is unified, and different proportions of income tax are deducted according to monthly income:

 Monthly income ⩽5,000 yuan, income tax: 0 yuan.

 5000<monthly income⩽15000, income tax: monthly income*5%.

 15,000<monthly income, income tax: monthly income*20%.

It is required to write 5 classes, namely: abstract class Employee, administrator class Admin, salesperson
class Salesman and worker class, and write demonstration class SalayDemo for testing.

It is required that these classes be placed in the cn.edu.gpnu.company package.

【Case Objective】

 Learn to analyze the logical ideas for realizing the task of "calculating employee wages".

 Able to independently complete the source code writing, compilation and operation of the "calculate employee salary" program.

 Master the knowledge points of inheritance in Java.

 Master the writing and use of abstract classes and abstract methods.

[Run results]
Insert image description here
[Run code]
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());

    }
}

Guess you like

Origin blog.csdn.net/m0_52703008/article/details/126200732