员工管理系统ArrayList 更新

来源:互联网 发布:noob厂 知乎 编辑:程序博客网 时间:2024/05/16 01:54

员工管理系统数组版
第一部分 案例描述
案例目的
学习面向对象的主要特征和基本概念,包括类、对象、继承、封装、多态、方法的重载和重写、Java的访问修饰符与其它关键字等。
案例难度
★★★
案例覆盖技能点
1、流程控制语句
2、类、对象
3、封装、继承、多态
4、方法的重载、重写
5、访问修饰符
6、static、finally
适用课程和对象
JAVA面向对象编程基础
第二部分 需求和开发环境
使用技术和开发环境
JEclipse3.0或以上、JDK7.0或以上
案例需求
需求说明:
员工信息的基本情况
————————————————————————
普通员工
属性:员工编号、员工姓名、员工职务、请假天数、基本工资
普通员工工资:
在基本工资的基础上增加10%的工作餐,50%的岗位补助,200元住房补助
基本工资+基本工资*0.1+基本工资*0.5+200
————————————————————————
经理
属性:员工编号、员工姓名、员工职务、请假天数、基本工资
经理工资:
在基本工资的基础上增加20%的工作餐,50%的岗位补助,500元住房补助
基本工资+基本工资*0.2+基本工资*0.5+500
————————————————————————
董事
属性:员工编号、员工姓名、员工职务、请假天数、基本工资
董事工资:
在基本工资的基础上增加8%的工作餐,30%的岗位补助,2000元住房补助,3000元投资补助
基本工资+基本工资*0.08+基本工资*0.3+2000+3000
————————————————————————
工资扣除部分,所有员工都一样
无请假,基本工资全发,有请假,扣除每天平均工资 * 请假天数

通过面向对象的编程思想,实现员工信息的增删改查,存储结构为数组。限定数组长度为100,业务流程如下
一、启动业务选择界面
这里写图片描述
二、增加员工
1.增加普通员工
这里写图片描述
2.增加经理
这里写图片描述
3.增加董事长
这里写图片描述
三、删除
这里写图片描述
四、修改
这里写图片描述
4、查询
这里写图片描述
4、查询所有

系统基本模块包括:
功能点 难度 备注


父类Employee类的创建 ★★★
三个子类:CommonEmployee类,Manager类和Director类的创建 ★★★
管理类TestEMD类——增加 ★★★★
管理类TestEMD类——删除 ★★★★
管理类TestEMD类——修改 ★★★★
管理类TestEMD类——查询 ★★★★


项目类汇总
这里写图片描述

**

代码如下:

**
com.jerry.employee.main 包:

public class TestEMD {    static Scanner sc = new Scanner(System.in);    static String[] employeelist = new String[100];    static int i = 0;    static Employee employee = new Employee();    static CommonEmployee common = new CommonEmployee();    static Director director = new Director();    static Manage manage = new Manage();    public static void main(String[] args) {        // TODO Auto-generated method stub        while (true) {            System.out.println("┏━━━ 业 务  选 项 ━━━┓\n"                              + "┃━━━━ 1.增加 ━━━━┃\n"                              + "┃━━━━ 2.删除 ━━━━┃\n"                             + "┃━━━━ 3.修改 ━━━━┃\n"                              + "┃━━━━ 4.查询 ━━━━┃\n"                              + "┃━━━ 5.查询所有 ━━━┃\n"                              + "┃━━━━ 0.退出 ━━━━┃\n"                             + "┗━━━ 业 务  选 项 ━━━┛");            System.out.println("请选择业务序号:");            int xuhao = sc.nextInt();            switch (xuhao) {            case 0:                System.out.println("您已退出系统,谢谢使用!");                break;            case 1:                TestEMD.addEmployee();                break;            case 2:                TestEMD.delEmployee();                break;            case 3:                TestEMD.updateEmployee();                break;            case 4:                TestEMD.queryEmployee();                break;            case 5:                TestEMD.queryAll();                break;            default:                System.out.println("请正确选择序号!");                main(args);                break;            }        }    }

com.jerry.employee.methods 包:

1 - CommonEmployee 类:

public class CommonEmployee extends Employee {    void Employee(String iD, String name, String position, int holiday, double salary) {        this.ID = iD;        this.name = name;        this.position = position;        this.holiday = holiday;        this.salary = salary;    }    /*     * 重写父类sumSalary方法     * @see com.jerry.employee.models.Employee#sumSalary()     */    public double sumSalary(double salary){        double newSalary = salary+salary*0.1+salary*0.5+200;        return newSalary;    }}

2 - Director 类

public class Director extends Employee {    void Employee(String iD, String name, String position, int holiday, double salary) {        this.ID = iD;        this.name = name;        this.position = position;        this.holiday = holiday;        this.salary = salary;    }    /*     *  重写父类sumSalary方法     * @see com.jerry.employee.models.Employee#sumSalary()     */    public double sumSalary(double salary) {        double newSalary = salary+salary*0.08+salary*0.3+2000+3000;        return newSalary;    }}

3 - Manage 类

public class Manage extends Employee {    void Employee(String iD, String name, String position, int holiday, double salary) {        this.ID = iD;        this.name = name;        this.position = position;        this.holiday = holiday;        this.salary = salary;    }    /*     * 重写父类sumSalary方法     * @see com.jerry.employee.models.Employee#sumSalary()     */    public double sumSalary(double salary) {        double newSalary = salary+salary*0.2+salary*0.5+500;        return newSalary;    }}

4-EmployeeManager类

public class EmployeeManager {    Scanner sc = new Scanner(System.in);    CommonEmployee common = new CommonEmployee();    Director director = new Director();    Manage manage = new Manage();    ArrayList<Employee> list = new ArrayList<Employee>();    /*     * 增加     */    public void addEmployee() {        Employee employee = new Employee();        System.out.println("请输入员工编号:");        String id = sc.next();        System.out.println("请输入员工姓名:");        String name = sc.next();        System.out.println("请输入员工职务(普通员工,经理,董事长):");        String position = sc.next();        System.out.println("请输入员工请假天数:");        int holiday = sc.nextInt();        System.out.println("请输入员工基本工资:");        double salary = sc.nextDouble();        employee.setID(id);        employee.setName(name);        employee.setPosition(position);        employee.setHoliday(holiday);        if ("普通员工".equals(position)) {            employee.setSalary(common.sumSalary(salary));        } else if ("经理".equals(position)) {            employee.setSalary(manage.sumSalary(salary));        } else if ("董事长".equals(position)) {            employee.setSalary(director.sumSalary(salary));        }        list.add(employee);        System.out.println("数据添加成功!");        System.out.println(employee.toString());    }    /*     * 删除     */    public void delEmployee() {        System.out.println("请输入要删除的员工姓名:");        String delName = sc.next();        System.out.println("您要删除的员工信息如下:");        int flag = 0;        for (int i = 0; i < list.size(); i++) {            if (list.contains(delName)) {                System.out.println(list.get(i));                flag = i;                break;            }        }        list.remove(flag);        System.out.println("数据删除成功!");    }    /*     * 修改     */    public void updateEmployee() {        Employee employee = new Employee();        System.out.println("请输入要修改的员工姓名:");        String updateName = sc.next();        System.out.println("您要修改的员工信息如下:");        int flag = 0;        for (int i = 0; i < list.size(); i++) {            if (list.contains(updateName)) {                System.out.println(list.get(i));                flag = i;                break;            }        }        System.out.println("请重新输入信息:");        System.out.println("请输入员工编号:");        String newId = sc.next();        System.out.println("请输入员工姓名:");        String newName = sc.next();        System.out.println("请输入员工职务(普通员工,经理,董事长):");        String newPosition = sc.next();        System.out.println("请输入员工请假天数:");        int newHoliday = sc.nextInt();        System.out.println("请输入员工基本工资:");        double newSalary = sc.nextDouble();        employee.setID(newId);        employee.setName(newName);        employee.setPosition(newPosition);        employee.setHoliday(newHoliday);        if ("普通员工".equals(newPosition)) {            employee.setSalary(common.sumSalary(newSalary));        } else if ("经理".equals(newPosition)) {            employee.setSalary(manage.sumSalary(newSalary));        } else if ("董事长".equals(newPosition)) {            employee.setSalary(director.sumSalary(newSalary));        }        list.set(flag, employee);        System.out.println("数据修改成功!");        System.out.println(list.get(flag));    }    /*     * 查询     */    public void queryEmployee() {        System.out.println("这是查询方法");        System.out.println("请输入要查找的员工姓名:");        String queryName = sc.next();        System.out.println("您要查找的员工信息如下:");        for (int i = 0; i < list.size(); i++) {            if (list.contains(queryName)) {                System.out.println(list.get(i));                break;            }        }    }    /*     * 查询所有信息     */    public void queryAll() {        System.out.println("所有员工信息如下:");        for (int i = 0; i < list.size(); i++) {            System.out.println(list.get(i));        }    }}

com.jerry.employee.methods 包:

public class Employee {    public String ID;    public String name;    public String position;    public int holiday;    public double salary;    /**     * 无参构造     */    public Employee() {        super();    }    /**     * 有参构造     * @param iD     * @param name     * @param position     * @param holiday     * @param salary     */    public Employee(String iD, String name, String position, int holiday, double salary) {        super();        ID = iD;        this.name = name;        this.position = position;        this.holiday = holiday;        this.salary = salary;    }    public String getID() {        return ID;    }    public void setID(String iD) {        ID = iD;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    public String getPosition() {        return position;    }    public void setPosition(String position) {        this.position = position;    }    public int getHoliday() {        return holiday;    }    public void setHoliday(int holiday) {        this.holiday = holiday;    }    public double getSalary() {        return salary;    }    public void setSalary(double salary) {        this.salary = salary;    }    @Override    public String toString() {        return "Employee [ID=" + ID + ", name=" + name + ", position=" + position + ", holiday=" + holiday + ", salary="                + salary + "]";    }    /*     * 父类方法,计算工资     */    public double sumSalary() {        return 0;    }}
0 0
原创粉丝点击