1.简单的企业人力资源管理系统功能图
作为一个信息管理系统,一般要有用户登录和退出这些基本功能,用户又可以有不同的级别,如管理员、部门经理和普通员工等,他们级别不同,在企业中所完成的工作也就有所不同。因此,通过分析,得到如图3-3所示的系统功能图。
企业人力资源管理系统功能图
2.系统分析
(1)系统启动时需要显示“登录、退出”两个主菜单,不同级别的用户登录后又会显示各自的功能子菜单。因此,可以设计一个Menu类,实现系统中菜单的显示和操作功能。
(2)管理员、部门经理和普通员工都属于企业员工,都具有“员工编号、登录密码、姓名、性别、所属部门、员工级别、工资”等相同的属性以及拥有如“个人信息维护”等相同的功能,所以可以设计一个Employee类来实现上述内容。
(3)设计一个StartMenu测试类,实现显示主菜单功能以及不同级别员工登录时显示不同级别的子菜单的功能。
3.代码实现
1)Employee类
package hrms.entity;
public class Employee{
private String empNo; //员工编号
private String password; //登陆密码
private String empName; //员工姓名
private String sex; //员工性别
private int empLevel; //员工级别(1表示普通员工;2表示部门经理;3表示管理员)
private String department; //所属部门
private double salary; //工资
//无参构造方法
public Employee(){
}
//有参构造方法
public Employee(String empNo,String password,String empName,String sex,int empLevel,String department,double salary){
super();
this.empNo=empNo;
this.password=password;
this.empName=empName;
this.sex=sex;
this.empLevel=empLevel;
this.department=department;
this.salary=salary;
}
/**
*显示员工信息
*/
public void dispInfo(){
String position=null;
if(empLevel==1) position="普通员工";
if(empLevel==2) position="部门经理";
if(empLevel==3) position="管理员";
System.out.println("**********************************************");
System.out.println("\t\t员工编号:"+empNo);
System.out.println("\t\t员工姓名:"+empName);
System.out.println("\t\t员工性别:"+sex);
System.out.println("\t\t员工级别:"+position);
System.out.println("\t\t所属部门:"+department);
System.out.println("\t\t工资:"+salary);
System.out.println("**********************************************");
}
//修改密码
public void modifyPassword(String newPassword){
this.password=newPassword;
System.out.println("密码修改成功");
}
//get/set方法
public String getEmpNo(){
return empNo;
}
public void setEmpNo(String empNo){
this.empNo=empNo;
}
public String getPassword(){
return password;
}
public void setPassword(String password){
this.password=password;
}
public String getEmpName(){
return empName;
}
public void setEmpName(String empName){
this.empName=empName;
}
public String getSex(){
return sex;
}
public void setSex(String sex){
this.sex=sex;
}
public String getEmpLevel(){
return empLevel;
}
public void setEmpLevel(int empLevel){
this.empLevel=empLevel;
}
public String getDepartment(){
return department;
}
public void setDepartment(String department){
this.department=department;
}
public String getSalary(){
return salary;
}
public void setSalary(double salary){
this.salary=salary;
}
}
2)Menu类
package hrms.entity;
import java.util.Scanner;
public class Menu{
Scanner input=new Scanner(System.in);
/**
*登陆主菜单
*/
public void showLoginMenu(){
System.out.println("\n\t\t\t欢迎进入企业人力资源管理系统\n");
System.out.println("******************************************");
System.out.println("\t\t\t1.登陆系统\n");
System.out.println("\t\t\t2.退出系统\n");
System.out.println("******************************************");
System.out.println("请输入菜单项数字:");
}
/**
*返回登陆菜单
*/
private void returnLoginMenu(){
boolean flag=true;
do{
String num=input.next();
if(num.toUpperCase().equals("R")){
flag=false;
showLoginMenu();
break;
}else{
System.out.prinln("具体功能留待以后实现,请输入r/R返回登陆菜单");
}
}while(flag);
}
/**
*普通员工菜单
*/
public void showStaffMenu(){
System.out.println("人力资源管理系统=>普通员工");
System.out.println("******************************************");
System.out.println("\t\t\t1.汇报工作\n");
System.out.println("\t\t\t2.查看个人信息\n");
System.out.println("\t\t\t3.修改密码\n");
System.out.println("\t\t\t4.查看考评信息\n");
System.out.println("\t\t\t5.查看工资等级\n");
System.out.println("\t\t\t6.今日工作内容\n");
System.out.println("******************************************");
System.out.println("请输入菜单项数字或输入r/R返回上一级菜单:");
returnLoginMenu(input);
}
/**
*部门经理菜单
*/
public void showManagerMenu(){
System.out.println("人力资源管理系统=>部门经理");
System.out.println("******************************************");
System.out.println("\t\t\t1.查看员工汇报工作\n");
System.out.println("\t\t\t2.考评员工\n");
System.out.println("\t\t\t3.查看个人信息\n");
System.out.println("\t\t\t4.修改密码\n");
System.out.println("\t\t\t5.查看工资等级\n");
System.out.println("\t\t\t6.今日工作内容\n");
System.out.println("******************************************");
System.out.println("请输入菜单项数字或输入r/R返回上一级菜单:");
returnLoginMenu(input);
}
/**
*管理员菜单
*/
public void showAdminMenu(){
System.out.println("人力资源管理系统=>管理员");
System.out.println("******************************************");
System.out.println("\t\t\t1.查看员工信息\n");
System.out.println("\t\t\t2.修改员工级别\n");
System.out.println("\t\t\t3.查看个人信息\n");
System.out.println("\t\t\t4.修改密码\n");
System.out.println("\t\t\t5.查看工资等级\n");
System.out.println("\t\t\t6.今日工作内容\n");
System.out.println("******************************************");
System.out.println("请输入菜单项数字或输入r/R返回上一级菜单:");
returnLoginMenu(input);
}
}
3)StartMenu类
public class StartMenu{
public static void main(String[] args){
//实例化普通员工
Employee staff=new Employee("0001","111","张三","男",1,"技术部",3000.5);
//实例化部门经理
Employee manager=new Employee("0002","222","李四","男",2,"技术部",4000.5);
//实例化管理员
Employee admin=new Employee("0003","333","王五","男",3,"技术部",5000.5);
//实例化菜单
Menu menu=new Menu();
//实例化登陆主菜单
menu.showLoginMenu();
//循环标志位
boolean flag=true;
Scanner input=new Scanner(System.in);
while(flag){
int choice=input.next();
//根据输入不同的选项进行不同功能操作
switch(choice){
case 1:System.out.println("请输入员工序号:");
String name=input.next();
System.out.println("请输入密码");
String password=input.next();
//如果是普通员工,显示普通员工菜单
if(name.equals(staff.getEmpNo())&&password.equals(staff.getPassword())){
menu.showStaffMenu();
}
//如果是经理,显示经理菜单
else if(name.equals(manager.getEmpNo())&&password.equals(manager.getPassword())){
menu.showManagerMenu();
}
//如果是管理员,显示管理员菜单
else if(name.equals(admin.getEmpNo())&&password.equals(admin.getPassword())){
menu.showAdminMenu();
}
else{
System.out.println("员工编号或者密码不对,请重新输入菜单项数字:");
menu.showLoginMenu();
}
break;
case 2:flag=false;
System.out.println("您退出了系统!");
break;
default:
System.out.println("输入选项不正确,请重新输入菜单项数字:");
menu.showLoginMenu();
break;
}
if(!flag) break;
}
}
}