本文主要是介绍实现Staff类的汇报工作功能,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
解决方案:
1创建汇报类Report
public class Report {//汇报类private int reportId;private int reporterId;private String content;public int getReportId() {return reportId;}public void setReportId(int reportId) {this.reportId = reportId;}public int getReporterId() {return reporterId;}public void setReporterId(int reporterId) {this.reporterId = reporterId;}public String getContent() {return content;}public void setContent(String content) {this.content = content;}}
2,创建Data数据初始化类
public class Data {//保存当前登录的员工public static Employee currentEmployee;//角色值为1普通员工 2经理 3 管理员//部门值1表示市场部 2表示开发部 3信息部//实例普通员工public static Staff staff=new Staff(1,"DH001","Staff","Staff",2,1,3000.5);//部门经理public static Manager manager=new Manager(2,"DH002","Manager","Manager",2,2,5000.5);//实例管理员public static Admin admin=new Admin(3,"DH003","Admin","Admin",2,3,4000.5);public static Report[] reports=new Report[1000];//初始化数据public static void init(){for(int i=0;i<reports.length;i++){reports[i]=new Report();}}}
3,创建业务逻辑类hrhelper
public class HrHelper {//登录检测public Employee login(String name,String password){if(name.equals(Data.staff .getUserName())&& password.equals(Data.staff.getPassword())){Data.currentEmployee=Data.staff ;}else if(name.equals(Data.manager.getUserName())&& password.equals(Data.manager.getPassword())){Data.currentEmployee=Data.manager ;}else if(name.equals(Data.admin.getUserName())&& password.equals(Data.admin.getPassword())){Data.currentEmployee=Data.admin;}return Data.currentEmployee;}public int getReportsCount(){int count=0;//如果遍历完现有汇报for(Report item:Data.reports){if(item.getReportId()<=0)break;count++;}//返回现有汇报数量return count;}//通过员工id返回员工对象public Employee getEmployeeByUserId(int userId){if(Data.staff.getUserId()==userId)return Data.staff;if(Data.manager.getUserId()==userId)return Data.manager;if(Data.admin.getUserId()==userId)return Data.admin;return null;}//显示所有汇报public void displayReports(){System.out.println("汇报如下");System.out.println("*****************************");for(int i=0;i<Data.reports.length;i++){//如果遍历完现有汇报if(Data.reports[i]==null)break;//得到汇报人信息Employee employee=getEmployeeByUserId(Data.reports[i].getReporterId());if(employee!=null)System.out.println("编号"+Data.reports[i].getReporterId()+"\t汇报人:"+employee.getUserName()+employee.getUserName()+"\t汇报内容:"+Data.reports[i].getContent());}}//添加汇报public void addReport(Report report){//得到当前汇报的数量int count =getReportsCount();if(count>=Data.reports.length){System.out.println("汇报日志已满");return;}else{//将汇报存储到report数组Data.reports[count]=report;System.out.println("汇报成功");}}/***修改员工角色*@param empNo 员工编号*@param roleName 角色名称**/public void modifyEmployeeRole(String empNo,String roleName){int roleId=0;switch(roleName){case "Staff":roleId=1;break;case "Manager":roleId=2;break;case "Admin":roleId=3;break;default:System.out.println("输入的角色不存在!");;break;}if(empNo.equals(Data.staff.getEmpNo())){Data.staff.setRoleId(roleId);}else if(empNo.equals(Data.manager.getRoleId())){Data.manager.setRoleId(roleId);}else if(empNo.equals(Data.admin.getRoleId())){Data.admin.setRoleId(roleId);}else{System.out.println("不存在此员工!");}}}
4 修改Staff类
public class Staff extends Employee{public Staff(){super();}public Staff(int userId,String empNo,String userName,String password,int departId,int roleId,double salary){super(userId,empNo,userName,password,departId,roleId,salary);}HrHelper helper=new HrHelper();public void addReport(){System.out.println("请输入汇报信息\n");Scanner input=new Scanner(System.in);String content=input.next();//实例化report对象Report report =new Report();//汇报id,每一次在上一次的基础上加一report.setReporterId(helper.getReportsCount()+1);report.setContent(content);//设置汇报人idreport.setReporterId(Data.currentEmployee.getUserId());//加入汇报数组helper.addReport(report);}}
这篇关于实现Staff类的汇报工作功能的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!