【JAVA】发奖金

文章目录

    • 题目
    • 项目层级结构
    • 解答
      • 程序的流程
      • UML图
      • 代码部分
        • Offer_reward.java
        • Staff.java
        • Techology.java
        • Management.java
        • Techological_Management.java
        • Intermediate_management.java
        • Intermediate_technologicalManagement.java
        • Intermediate_technology.java
        • Primary_management.java
        • Primary_technologicalManagement.java
        • Primary_technology.java
        • Supreme_management
        • Supreme_technologicalManagement
        • Supreme_technology
      • 运行结果
    • 结语

题目

某软件公司年末奖金发放现在需要给公司员工发奖金,其中员工属性有以下五种

  • 编号
  • 姓名
  • 员工类别
  • 总工作量 ( x ) (x) (x)
  • 奖金 ( y ) (y) (y)

其中员工类别分为

  • 技术类
  • 管理类
  • 技术管理类

各个类别的奖金颁发如下

  1. 技术类
    y = { x ∗ 30 高级工程师 x ∗ 25 中级工程师 x ∗ 20 初级工程师 y=\begin{cases} &x*30 &高级工程师\\ &x*25 &中级工程师\\ &x*20 &初级工程师 \end{cases} y= x30x25x20高级工程师中级工程师初级工程师
  2. 管理类
    y = { x ∗ 15 高管 ( x − 50 ) ∗ 10 中层管理人员 ( x − 100 ) ∗ 5 普通管理职员 y=\begin{cases} &x*15 &高管\\ &(x-50)*10 &中层管理人员\\ &(x-100)*5 &普通管理职员 \end{cases} y= x15(x50)10(x100)5高管中层管理人员普通管理职员
  3. 技术管理类
    y = { x ∗ 25 + 100 高级技术管理类 x ∗ 25 + 70 中级技术管理类 x ∗ 25 + 50 初级技术管理类 y=\begin{cases} &x*25+100 &高级技术管理类\\ &x*25+70 &中级技术管理类\\ &x*25+50 &初级技术管理类 \end{cases} y= x25+100x25+70x25+50高级技术管理类中级技术管理类初级技术管理类

要求选定一个员工类别,输入工作量,输出奖金并且运用面向对象的思想。


项目层级结构


├─.idea
│      .gitignore
│      misc.xml
│      modules.xml
│      uiDesigner.xml
│      workspace.xml
│      
├─out
│  └─production
│      └─HW2
│              Intermediate_management.class
│              Intermediate_technologicalManagement.class
│              Intermediate_technology.class
│              Management.class
│              Offer_reward.class
│              Primary_management.class
│              Primary_technologicalManagement.class
│              Primary_technology.class
│              Staff.class
│              Supreme_management.class
│              Supreme_technologicalManagement.class
│              Supreme_technology.class
│              Technical_Management.class
│              Technology.class
│              
└─src
        Intermediate_management.java
        Intermediate_technologicalManagement.java
        Intermediate_technology.java
        Management.java
        Offer_reward.java
        Primary_management.java
        Primary_technologicalManagement.java
        Primary_technology.java
        Staff.java
        Supreme_management.java
        Supreme_technologicalManagement.java
        Supreme_technology.java
        Technical_Management.java
        Technology.java
        


解答

解答大致分为四部分:程序流程 \ UML \ 代码 \ 运行结果

程序的流程

  1. 输入员工工种的大分支(技术类、管理类、技术管理类);
  2. 继续输入当前工种的小分支(初级、中级、高级);
  3. 最后输入该员工的工作时常;
  4. 最后输出该员工的工资staff_reward;

UML图

【JAVA】发奖金_第1张图片


代码部分

该完整代码分为若干个类,并且有普通类也有抽象类,详情请看上方的UML

Offer_reward.java

import java.util.Scanner;

public class Offer_reward {
    public static void main(String[] args) {
        Staff staff = new Staff();
        staff.setStaff_type();
        System.out.println("请输入其工作量");
        Scanner scanner = new Scanner(System.in);
        staff.setStaff_workTime(scanner.nextInt());
        if(staff.staff_type == "初级技术工程师"){
            Primary_technology primary_technology = new Primary_technology();
            primary_technology.setReward(staff.staff_workTime);
//          假如staff_reward不是私有变量则可以这样表示  System.out.println("该员工工资为" + primary_technology.staff_reward);
            int reward = primary_technology.getReward(staff.staff_workTime);
            System.out.println("该员工工资为" + reward);
        }
        if (staff.staff_type == "中级技术工程师"){
            Intermediate_technology intermediate_technology = new Intermediate_technology();
            intermediate_technology.setReward(staff.staff_workTime);
//            System.out.println("该员工工资为" + intermediate_technology.staff_reward);
            int reward = intermediate_technology.getReward(staff.staff_workTime);
            System.out.println("该员工工资为" + reward);
        }
        if (staff.staff_type == "高级技术工程师"){
            Supreme_technology supreme_technology = new Supreme_technology();
            supreme_technology.setReward(staff.staff_workTime);
            //System.out.println("该员工工资为" + supreme_technology.staff_reward);
            int reward = supreme_technology.getReward(staff.staff_workTime);
            System.out.println("该员工工资为" + reward);
        }
        if (staff.staff_type == "普通管理人员"){
            Primary_management primary_management = new Primary_management();
            primary_management.setReward(staff.staff_workTime);
            //System.out.println("该员工工资为" + primary_management.staff_reward);
            int reward = primary_management.getReward(staff.staff_workTime);
            System.out.println("该员工工资为" + reward);
        }
        if (staff.staff_type == "中层管理人员"){
            Intermediate_management intermediate_management = new Intermediate_management();
            intermediate_management.setReward(staff.staff_workTime);
            //System.out.println("该员工工资为" + intermediate_management.staff_reward);
            int reward = intermediate_management.getReward(staff.staff_workTime);
            System.out.println("该员工工资为" + reward);
        }
        if (staff.staff_type == "高管"){
            Supreme_management supreme_management = new Supreme_management();
            supreme_management.setReward(staff.staff_workTime);
            //System.out.println("该员工工资为" + supreme_management.staff_reward);
            int reward = supreme_management.getReward(staff.staff_workTime);
            System.out.println("该员工工资为" + reward);
        }
        if (staff.staff_type == "初级技术管理"){
            Primary_technologicalManagement primary_technologicalManagement = new Primary_technologicalManagement();
            primary_technologicalManagement.setReward(staff.staff_workTime);
           //System.out.println("该员工工资为" + primary_technologicalManagement.staff_reward);
            int reward = primary_technologicalManagement.getReward(staff.staff_workTime);
            System.out.println("该员工工资为" + reward);
        }
        if (staff.staff_type == "中级技术管理"){
            Intermediate_technologicalManagement intermediate_technologicalManagement = new Intermediate_technologicalManagement();
            intermediate_technologicalManagement.setReward(staff.staff_workTime);
            //System.out.println("该员工工资为" + intermediate_technologicalManagement.staff_reward);
            int reward = intermediate_technologicalManagement.getReward(staff.staff_workTime);
            System.out.println("该员工工资为" + reward);
        }
        if (staff.staff_type == "高级技术管理"){
            Supreme_technologicalManagement supreme_technologicalManagement = new Supreme_technologicalManagement();
            supreme_technologicalManagement.setReward(staff.staff_workTime);
            //System.out.println("该员工工资为" + supreme_technologicalManagement.staff_reward);
            int reward = supreme_technologicalManagement.getReward(staff.staff_workTime);
            System.out.println("该员工工资为" + reward);

        }
    }
}

Staff.java

import java.util.Scanner;

public class Staff {
    int staff_no;
    String staff_name;
    int staff_workTime;
    private int staff_reward;
    String staff_type;
    void setStaff_type(){
        System.out.println("请输入总员工总类的编号:1为技术类、2为管理类、3为技术管理类");
        Scanner scanner = new Scanner(System.in);
        int type = scanner.nextInt();
        if (type == 1){
            System.out.println("当前为技术类,请输入当前员工详细类的等级:1为初级,2为中级,3为高级");
            Scanner scanner1 = new Scanner(System.in);
            int detailType = scanner1.nextInt();
            switch (detailType){
                case 1:
                    this.staff_type = "初级技术工程师";
                    break;
                case 2:
                    this.staff_type = "中级技术工程师";
                    break;
                case 3:
                    this.staff_type = "高级技术工程师";
                    break;
            }
        }
        if (type == 2){
            System.out.println("当前为管理类,请输入当前员工详细类的等级:1为普通,2为中层,3为高管");
            Scanner scanner1 = new Scanner(System.in);
            int detailType = scanner1.nextInt();
            switch (detailType) {
                case 1:
                    this.staff_type = "普通管理人员";
                    break;
                case 2:
                    this.staff_type = "中层管理人员";
                    break;
                case 3:
                    this.staff_type = "高管";
                    break;
            }
        }
        if (type == 3){
            System.out.println("当前为技术管理类,请输入当前员工详细类的等级:1为初级,2为中级,3为高级");
            Scanner scanner1 = new Scanner(System.in);
            int detailType = scanner1.nextInt();
            switch (detailType) {
                case 1:
                    this.staff_type = "初级技术管理";
                    break;
                case 2:
                    this.staff_type = "中级技术管理";
                    break;
                case 3:
                    this.staff_type = "高级技术管理";
                    break;
            }
        }
    }
    void setStaff_workTime(int workTime){
        this.staff_workTime = workTime;
    }
    void setReward(int staff_workTime){}
    int getReward(int staff_workTime){ return staff_reward;}
}

Techology.java

abstract class Technology extends Staff{
    abstract int getReward(int workTime);
    abstract void setReward(int workTime);
}

Management.java

import javax.swing.text.TabSet;

abstract class Management extends Staff{
    abstract int getReward(int workTime);
    abstract void setReward(int workTime);
}

Techological_Management.java

import javax.swing.text.TabSet;

abstract class Technical_Management extends Staff{
    abstract int getReward(int workTime);
    abstract void  setReward(int workTime);
}

Intermediate_management.java

public class Intermediate_management extends Management{
    int staff_reward;
    @Override
    int getReward(int workTime) {
        return (workTime - 50) * 10;
    }
    void setReward(int workTime){
        this.staff_reward = (workTime - 50) * 10;
    }
}

Intermediate_technologicalManagement.java

public class Intermediate_technologicalManagement extends Technical_Management{
    int staff_reward;
    @Override
    int getReward(int workTime) {
        return workTime * 25 + 70;
    }
    void setReward(int workTime){
        this.staff_reward = workTime * 25 + 70;
    }
}

Intermediate_technology.java

public class Intermediate_technology extends Technology{
    int staff_reward;
    @Override
    int getReward(int workTime) {
        return workTime*25;
    }
    void setReward(int workTime){
        this.staff_reward = workTime*25;
    }
}

Primary_management.java

public class Primary_management extends Management{
    int staff_reward;
    @Override
    int getReward(int workTime) {
        return (workTime - 100) * 5;
    }
    void setReward(int workTime){
        this.staff_reward = (workTime - 100) * 5;
    }
}

Primary_technologicalManagement.java

public class Primary_technologicalManagement extends Technical_Management{
    int staff_reward;
    @Override
    int getReward(int workTime) {
        return workTime*25 + 50;
    }
    void  setReward(int workTime){
        this.staff_reward = workTime*25 + 50;
    }
}

Primary_technology.java

public class Primary_technology extends Technology{
    int staff_reward;
    @Override
    int getReward(int workTime) {
       return workTime*20;
    }
    void setReward(int workTime){
        this.staff_reward = workTime * 20;
    }
}

Supreme_management

public class Supreme_management extends Management{
    int staff_reward;
    @Override
    int getReward(int workTime) {
        return workTime * 15;
    }
    void setReward(int workTime){
        this.staff_reward = workTime * 15;
    }
}

Supreme_technologicalManagement

public class Supreme_technologicalManagement extends Technical_Management{
    int staff_reward;
    @Override
    int getReward(int workTime) {
        return workTime * 25 + 100;
    }
    void setReward(int workTime){
        this.staff_reward = workTime * 25 + 100;
    }
}

Supreme_technology

public class Supreme_technology extends Technology{
    int staff_reward;
    @Override
    int getReward(int workTime) {
        return workTime*30;
    }
    void setReward(int workTime){
        this.staff_reward = workTime*30;
    }
}


运行结果

【JAVA】发奖金_第2张图片


结语

如果有疑问欢迎大家留言讨论,你如果觉得这篇文章对你有帮助可以给我一个免费的赞吗?我们之间的交流是我最大的动力!

你可能感兴趣的:(JAVA,java,开发语言)