Java第四周员工管理系统集合版

**第一部分 案例描述
案例目的
学习面向对象的主要特征和基本概念,包括类、对象、继承、封装、多态、方法的重载和重写、Java的访问修饰符与其它关键字以及集合等。
案例难度
★★★
案例覆盖技能点
1、流程控制语句
2、类、对象
3、封装、继承、多态
4、方法的重载、重写
5、访问修饰符
6、static、finally
7、集合
适用课程和对象
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
工资扣除部分,所有员工都一样
无请假,基本工资全发,有请假,扣除每天平均工资 * 请假天数

具体实现步骤:
1.新建工程StaffManagement,包名:my.employee
2.添加员工类Employee, 该类中主要属性及方法:**

实现过程代码:
1、员工类Employee, 该类中主要属性及方法:
package test9_10StaffManagement;
/***
 * 2.添加员工类Employee, 该类中主要属性及方法:
 * @author HP-Developer
 *属性:员工编号、员工姓名、员工职务、请假天数、基本工资
 */
public class Employee  {

    private String ID;
    private String name;
    private String position;
    private int holiday;
    private double salary;

    public Employee( String ID,String name,String postion,int holiday,double salary, String position){
        super();
        this.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;
    }

    public double sumSalary(int holiday){
        return 1;

    }

    public void display(){
        System.out.println("编号:"+this.ID+"姓名:"+this.name
                +"职务:"+this.position+"请假天数:"+this.holiday+"工资:"+this.sumSalary(this.holiday));

    }


}
2package test9_10StaffManagement;
/***
 * 3.添加懂事类Director继承于员工类Employee, 该类中构造方法及薪水方法:
 * @author HP-Developer
 *董事工资:
    在基本工资的基础上增加8%的工作餐,30%的岗位补助,2000元住房补助,3000元投资补助
    基本工资+基本工资*0.08+基本工资*0.3+2000+3000
 */
public class Director  extends Employee {

    public Director(String ID, String name, String postion, int holiday,
            double salary, String position) {
        super(ID, name, postion, holiday, salary, position);
        this.setID(ID);
        this.setName(name);
        this.setPosition(position);
        this.setHoliday(holiday);
        this.setSalary(salary);

    }

    public double sumSalary(int holiday){
        return (this.getSalary()*1.38+5000)/30*(30-this.getHoliday());

    }
}
3package test9_10StaffManagement;
/***
 * 4.参照类Director添加经理类Manager,Manager也继承于员工类Employee
 * @author HP-Developer
 * 在基本工资的基础上增加20%的工作餐,50%的岗位补助,500元住房补助
      基本工资+基本工资*0.2+基本工资*0.5+500
 */
public class Manager  extends Employee {

    public Manager(String ID, String name, String postion, int holiday,
            double salary, String position) {
        super(ID, name, postion, holiday, salary, position);
        this.setID(ID);
        this.setName(name);
        this.setPosition(position);
        this.setHoliday(holiday);
        this.setSalary(salary);

    }

    public double sumSalary(int holiday){
        return (this.getSalary()*1.7+500)/30*(30-this.getHoliday());

    }
}
4package test9_10StaffManagement;
/***
 * 5.参照类Director添加普通员工类CommonEmployee,
 * CommonEmployee也继承于员工类Employee
 * @author HP-Developer
 * @data 2015-9-10
 * 普通员工工资:
    在基本工资的基础上增加10%的工作餐,50%的岗位补助,200元住房补助
    基本工资+基本工资*0.1+基本工资*0.5+200
 * 
 */
public class CommonEmployee  extends Employee {

    public CommonEmployee(String ID, String name, String postion, int holiday,
            double salary, String position) {
        super(ID, name, postion, holiday, salary, position);
        this.setID(ID);
        this.setName(name);
        this.setPosition(position);
        this.setHoliday(holiday);
        this.setSalary(salary);

    }

    public double sumSalary(int holiday){
        return (this.getSalary()*1.6+500)/30*(30-this.getHoliday());

    }
}
5package test9_10StaffManagement;

import java.util.ArrayList;
import java.util.Scanner;

/***
 *  新建数组列表类对象,用于保存员工信息
 * 增加
 * addEmployee(){}
 * 删除员工信息方法:
 *  public  void delEmployee(){ }
   更新员工信息方法
    public  void updateEmployee(){  } 
   查询员工信息方法:
    public  void queryEmployee(){   }
 * @author HP-Developer
 * @data 2015-9-10
 */
public class EmployeeInformationPro {

    public static ArrayList<Employee> ems=new ArrayList();
    /***
     *1 添加员工信息方法:
     */
    public void addEmployee(){
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入员工编号:");
        String id=sc.nextLine();
        System.out.println("请输入员工姓名:");
        String name=sc.nextLine();
        System.out.println("请输入员工职务(提示输入:employee,manager,chairman):");
        String position=sc.nextLine();
        System.out.println("请输入员工请假天数:");
        int holiday=sc.nextInt();
        System.out.println("请输入员工基本工资:");
        double salary=sc.nextDouble();

        if(position.equals("employee")){
            Employee newOne=new CommonEmployee(id, name, position, holiday, salary, position);
            ems.add(newOne);
            System.out.println("添加数据成功!");
            newOne.display();
        } else if(position.equals("manager")){
            Employee newOne=new Manager(id, name, position, holiday, salary, position);
            ems.add(newOne);
            System.out.println("添加数据成功!");
            newOne.display();
        } else if(position.equals("chairman")){
            Employee newOne=new Director(id, name, position, holiday, salary, position);
            ems.add(newOne);
            System.out.println("添加数据成功!");
            newOne.display();
        }else {
            System.out.println("亲,你输入的内容,难以识别!");
        }


    }
    //删除员工信息方法:
     public  void delEmployee(){

            Scanner sc=new Scanner(System.in);
            System.out.println("请输入删除员工信息的员工编号:");
            String id=sc.nextLine();


            for(int i=0;i<ems.size();i++){
                   if( id.equals(ems.get(i).getID())){
                       ems.remove(ems.get(i));
                      }
            }
                System.out.println("亲,删除员工信息完成!");
     }
    // 更新员工信息方法;
     public  void updateEmployee(){ 
         Scanner sc=new Scanner(System.in);
            System.out.println("请输入 更新员工信息的员工编号:");
            String id=sc.nextLine();

             for(int i=0;i<ems.size();i++){
                   if( id.equals(ems.get(i).getID())){
                    System.out.println("请输入员工姓名:");
                    String name=sc.nextLine();
                    ems.get(i).setName(name);
                    System.out.println("请输入员工职务(提示输入:employee,manager,chairman):");
                    String position=sc.nextLine();
                    ems.get(i).setPosition(position);
                    System.out.println("请输入员工请假天数:");
                    int holiday=sc.nextInt();
                    ems.get(i).setHoliday(holiday);   
                    System.out.println("请输入员工基本工资:");
                    double salary=sc.nextDouble();
                    ems.get(i).setSalary(salary);
                    System.out.println("亲,更新员工信息完成!");
                    ems.get(i).display();

                      }
            }





     } 
     // 查询员工信息方法:
     public  void queryEmployee(){ 
         Scanner sc=new Scanner(System.in);
            System.out.println("请输入查询员工编号:");
            String id=sc.nextLine();
            for(int i=0;i<ems.size();i++){
                   if( id.equals(ems.get(i).getID())){
                       ems.get(i).display();
                       System.out.println();
                      }
            }

     }

}
6package test9_10StaffManagement;

import java.util.Scanner;
/***
 * 测试类来运行一下!
 * @author HP-Developer
 *
 */
public class TestEmployee {
     static EmployeeInformationPro em=new EmployeeInformationPro();
  public static void main(String[] args) {

      show();
      test();

}
  public static void show(){
      boolean choice=true;
      while(choice){
        System.out.println("||--------------||");  
        System.out.println("||----1、增加-----||");  
        System.out.println("||----2、删除-----||");  
        System.out.println("||----3、修改-----||");  
        System.out.println("||----4、查询-----||");  
        System.out.println("||----0退出-----||");  
        System.out.println("||--------------||");  
        System.out.println("请选择业务,请输入数字:"); 
        choice=false;
      }
  }
  public  static void test(){

      Scanner input=new Scanner(System.in);
      int choice=input.nextInt();
      switch(choice){
      case 1:
          em.addEmployee();
          show();
          test();
          break;
      case 2:
          em.delEmployee();
          show();
          test();
          break;
      case 3:
          em.updateEmployee();
          show();
          test();
          break;
      case 4:
          em.queryEmployee();
          show();
          test();
          break;
      case 0:
          System.out.println("退出成功!");
          System.exit(choice);
          break;
      default:
        System.out.println("对不起,您输入有误!");
        show();
         test();
          break;
      }
  }
}
/***运行结果:
 * ||--------------||
||----1、增加-----||
||----2、删除-----||
||----3、修改-----||
||----4、查询-----||
||----0退出-----||
||--------------||
请选择业务,请输入数字:
1
请输入员工编号:
1
请输入员工姓名:
malin
请输入员工职务(提示输入:employee,manager,chairman):
chairman
请输入员工请假天数:
1
请输入员工基本工资:
10900000
添加数据成功!
编号:1姓名:malin职务:chairman请假天数:1工资:1.4545433333333332E7
||--------------||
||----1、增加-----||
||----2、删除-----||
||----3、修改-----||
||----4、查询-----||
||----0退出-----||
||--------------||
请选择业务,请输入数字:
2
请输入删除员工信息的员工编号:
1
亲,删除员工信息完成!
||--------------||
||----1、增加-----||
||----2、删除-----||
||----3、修改-----||
||----4、查询-----||
||----0退出-----||
||--------------||
请选择业务,请输入数字:
4
请输入查询员工编号:
1
||--------------||
||----1、增加-----||
||----2、删除-----||
||----3、修改-----||
||----4、查询-----||
||----0退出-----||
||--------------||
请选择业务,请输入数字:

 */




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

苦思冥想行则将至

穷,有钱的大爷上个两分钱吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值