学习日常----Java实现打印公司员工的信息列表

题目要求:
   输出一组公司员工的信息列表,其中员工具备以下特征:
   雇员:员工编号、姓名、工资;
   经理:员工编号、姓名、工资、管理部门;
   总监:员工编号、姓名、工资、津贴;
知识点分析:通过继承完成各类员工的定义,通过方法重载进行员工信息的输出
首先定义Employee类
class Employee {
    String no;
    String name;
    int money;
    public Employee(String no, String name, int money){

        this.no=no;
        this.name=name;
        this.money=money;

    }
    public void showInfo(){
        System.out.println("员工编号:"+no+","+"员工姓名:"+name+","+"员工工资:"+money);

    }
}

 

其次定义Manager类与Header类继承与Employee类
public class Manager extends Employee {
    String department;
    public Manager(String no, String name, int money, String department) {

        super(no, name, money);
        this.department=department;
    }
    public void showInfo(){
        super.showInfo();
        System.out.println("管理部门:"+department);

    }
}
public class Header extends Employee {
    int jintie;
    public Header(String no, String name, int money, int jintie) {
        super(no, name, money);
        this.jintie=jintie;

    }
    public void showInfo(){
        super.showInfo();
        System.out.println("津贴:"+jintie);
    }
}

 



定义主函数:
public class TestEmployee {
    public static void main(String[] args){
        Employee e1=new Employee("001","金子博",2000);
        Employee e2=new Employee("002","郭禹",2000);
        Employee e3=new Employee("003","刘炳呈",2000);


        Manager m4=new Manager("004","小李",3000,"市场管理部");
        Manager m5=new Manager("005","小明",4000,"销售部");


        Header h6=new Header("006","小孙",4000,200);
        e1.showInfo();
        e2.showInfo();
        e3.showInfo();

        m4.showInfo();
        m5.showInfo();

        h6.showInfo();

    }
}

 

 
 
posted @ 2020-10-19 10:52  AA、  阅读(1031)  评论(0编辑  收藏  举报