Java第四周员工管理系统集合版
来源:互联网 发布:小知科技 严飞 编辑:程序博客网 时间:2024/04/30 08:15
**第一部分 案例描述
案例目的
学习面向对象的主要特征和基本概念,包括类、对象、继承、封装、多态、方法的重载和重写、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)); }}2、package 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()); }}3、package 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()); }}4、package 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()); }}5、package 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(); } } }}6、package 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退出-----||||--------------||请选择业务,请输入数字: */
- Java第四周员工管理系统集合版
- 员工管理系统(集合版)
- 员工管理系统集合框架版
- 员工管理系统集合版本
- java 员工管理系统
- java集合的运用:控制台简单员工管理系统
- java【源码】员工管理系统
- java 简单员工管理系统
- Java基础练习2之用集合写员工管理系统
- 员工管理系统数组版
- 员工管理系统数组版
- 员工管理系统Android版
- 员工管理系统Map版
- 员工管理系统List版
- Java实现员工管理系统(数据库存储版)
- 集合 员工薪水管理
- Java员工管理系统(控制台输出)
- 员工管理系统数组版-建立员工类
- HttpClient使用详解
- valgrind检测内存泄漏
- 游戏程序流、状态处理机、进程管理器、数据包系统的实现
- 单词排序
- TextView富文本显示
- Java第四周员工管理系统集合版
- android隐藏标题栏和状态栏
- heartbeat: ha.cf配置文件中文详解
- 如何在spring项目中使用shiro进行权限管理
- piwik的一些坑
- 关于poi/Npoi创建批注后,EXCEL不能显示,wps能显示的问题
- socket中的函数遇见EINTR的处理
- Skitch 图片注释软件(推荐)
- html ajax 简单封装