Java实现部门员工管理

2022-10-07,,,

本文实例为大家分享了java实现部门员工管理的具体代码,供大家参考,具体内容如下

项目作业:部门员工管理

题目要求:

某公司要开发内部的 “办公信息化管理系统”,请使用面向对象的思想描述以下员工信息。

程序运行参考效果图如下:

任务描述

一、程序整体要求

划分功能模块,根据题目要求设置不同的包和类,在类中实现相应功能的管理。

类的标识要清楚易懂,代码结构要层次分明,代码编辑思路要清晰、整洁。

要求java代码书写、命名符合规范,属性所属数据类型要准确合理,在代码中添加必要的注释,程序运行效果与提供的页面效果图、结构保持一致,信息间分隔符“=”号数量不做统一要求,文字大小、颜色也不做统一要求,将作业项目形成压缩文件并提交。 

二、思路分析

由场景和运行效果,可以分析出项目中可以抽取如下类(要求编码时注意面向对象思想及封装特性的应用):

1、部门类:

类型描述:能够描述部门编号、部门名称、员工数组、统计部门中的员工个数

要求:设定方法统计该部门员工个数

提示:部门类的属性有四个,分别是部门编号,部门名称,员工数组 和 统计变量 ,具体是市场部还是人事部,是通过部门类的对象来表示的,如果是市场部的对象,那么添加并统计的就是市场部的人数,同样如果是人事部的对象,添加并统计的就是人事部的人数。

2、职务类:

类型描述:能够描述职务编号、职务名称。

3、员工类:

类型描述:能够描述员工姓名、工号、年龄、性别、所属部门、职务信息

要求:

1、 设定方法限定年龄只能是18--65之间,反之则设置默认为18岁

2、 设定方法限定性别只能是“男”或者“女”,反之则设置默认为"男"(使用字符串的equals()方法)

3、 设定方法,实现员工自我介绍信息,将员工信息作为字符串返回

 4、测试类:

类型描述:测试程序,并参照效果图输出结果

注意:可以在属性上添加适当的信息验证,提高信息的安全性

评分标准:

1、规范【10分】   

每个类都封装在自己独立的 ".java"文件中;

文件、class、成员变量命名规范;                   

代码结构要层次分明;  

java代码规范及添加适量注释。

2、程序整体运行效果【10分】 

程序正常运行效果,且满足效果图要求。信息间分隔符“=”号数量不做统一要求

3、部门类【22分】

能够描述部门编号、部门名称、获取所有该部门员工信息;设定方法,完成统计该部门员工个数的功能

4、职务类【6分】

能够描述职务编号、职务名称

5、员工类【34分】

能够描述员工姓名、工号、年龄、性别、所属部门、职务信息;

设定方法来约束年龄的范围;

设定方法来限定性别的选择;

设定方法,实现员工自我介绍信息,将员工信息作为字符串返回

6、测试类【18分】

测试程序,将题目中的员工信息传入到程序中,参照效果图输出结果

package com.staff;
 
//部门类
public class department{
  private string dnumber;    //部门编号
  private string dname;      //部门名称
  private staff[] staff=new staff[10];  //定义一个staff类的员工数组
  private int staffnum;      //员工人数
  public void setdnumber(string dnumber)
  {
      this.dnumber=dnumber;
  }
  public string getnumb0er()
  {
      return dnumber;
  }
  public void setdname(string dname)
  {
      this.dname=dname;
 
  }
  public string getdname(){
      return dname;
  }
  public  void setstaff(staff staff[])
  {
      this.staff=staff;
 
  }
  public staff[] getstaff()
  {
      return staff;
 
  }
  public void setstaffnum(int staffnum)
  {
      this.staffnum=staffnum;
 
  }
  public int getstaffnum()
  {
      return staffnum;
 
  }
  //定义构造方法,获得dnumber和dname的值
  public department(string dnumber,string dname){
      this.setdnumber(dnumber);
      this.setdname(dname);
  }
  /*将员工保存到数组中*/
  public void togetherstaff(staff sta){
      for (int i=0;i<this.getstaff().length;i++){
          if(this.getstaff()[i]==null){
              this.getstaff()[i]=sta;
              this.staffnum=i+1;
              return;
          }
      }
  }
}
package com.staff;
 
//职务类
public class office{
  private string onumber;   //职务编号
  private string oname;     //职务名称
  public void setonumber(string onumber)
  {
      this.onumber=onumber;
 
  }
  public string getonumber(){
 
      return onumber;
  }
  public void setoname(string oname){
 
      this.oname=oname;
  }
  public string getoname()
  {
      return oname;
 
  }
  //定义构造方法,获得onumber和oname的值
  public office(string onumber,string oname){
      this.setonumber(onumber);
      this.setoname(oname);
  }
}
package com.staff;
 
//员工类
public class staff{
  private string name;     //员工姓名
  private string number;   //员工工号
  private int age;         //员工年龄
  private string sex;      //员工性别
  private department department;  //员工所属部门
  private office officeinfo;      //员工职务信息
 
  public void setname(string name){
 
      this.name=name;
  }
  public string getname(){
 
      return name;
  }
  public void setnumber(string number){
 
      this.number=number;
  }
  public string getnumber(){
 
      return number;
  }
  public void setage(int age){
      if (age<18||age>65){
          system.out.println("年龄只能在18~65岁之间,如果不在,则默认为18岁");
          this.age=18;
      }
      else
          this.age=age;
  }
  public int getage(){
 
      return age;
  }
  public void setsex(string sex){
      if(!sex.equals("男") && !sex.equals("女")){
          system.out.println("输入性别有误,默认值为男");
          this.sex="男";
      }
      else
          this.sex=sex;
  }
  public string getsex(){
 
      return sex;
  }
 
  public void setdepartment(department department) {
 
      this.department=department;
  }
  public department getdepartment(){
 
      return department;
  }
 
  public void setofficeinfo(office officeinfo) {
 
      this.officeinfo = officeinfo;
  }
  public office getofficeinfo(){
 
      return officeinfo;
  }
  //定义构造方法,分别获得员工姓名,员工工号,员工性别,员工姓名,员工所属部门,员工职务信息
  public staff(string name,string number,string sex,int age,department department,office officeinfo){
      this.setname(name);
      this.setnumber(number);
      this.setsex(sex);
      this.setage(age);
      this.setdepartment(department);
      this.setofficeinfo(officeinfo);
  }
  //定义普通方法,返回员工所有基本信息
  public string staffintroduction(){
      return "姓名:"+ this.getname()+"\n工号:"+ this.getnumber()+"\n年龄:"+ this.getage()+"\n性别:"+ this.getsex()+"\n职务:"+ this.getdepartment().getdname()+ this.getofficeinfo().getoname();
  }
}
package com.staff;
 
//员工类
public class staff{
  private string name;     //员工姓名
  private string number;   //员工工号
  private int age;         //员工年龄
  private string sex;      //员工性别
  private department department;  //员工所属部门
  private office officeinfo;      //员工职务信息
 
  public void setname(string name){
 
      this.name=name;
  }
  public string getname(){
 
      return name;
  }
  public void setnumber(string number){
 
      this.number=number;
  }
  public string getnumber(){
 
      return number;
  }
  public void setage(int age){
      if (age<18||age>65){
          system.out.println("年龄只能在18~65岁之间,如果不在,则默认为18岁");
          this.age=18;
      }
      else
          this.age=age;
  }
  public int getage(){
 
      return age;
  }
  public void setsex(string sex){
      if(!sex.equals("男") && !sex.equals("女")){
          system.out.println("输入性别有误,默认值为男");
          this.sex="男";
      }
      else
          this.sex=sex;
  }
  public string getsex(){
 
      return sex;
  }
 
  public void setdepartment(department department) {
 
      this.department=department;
  }
  public department getdepartment(){
 
      return department;
  }
 
  public void setofficeinfo(office officeinfo) {
 
      this.officeinfo = officeinfo;
  }
  public office getofficeinfo(){
 
      return officeinfo;
  }
  //定义构造方法,分别获得员工姓名,员工工号,员工性别,员工姓名,员工所属部门,员工职务信息
  public staff(string name,string number,string sex,int age,department department,office officeinfo){
      this.setname(name);
      this.setnumber(number);
      this.setsex(sex);
      this.setage(age);
      this.setdepartment(department);
      this.setofficeinfo(officeinfo);
  }
  //定义普通方法,返回员工所有基本信息
  public string staffintroduction(){
      return "姓名:"+ this.getname()+"\n工号:"+ this.getnumber()+"\n年龄:"+ this.getage()+"\n性别:"+ this.getsex()+"\n职务:"+ this.getdepartment().getdname()+ this.getofficeinfo().getoname();
  }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

《Java实现部门员工管理.doc》

下载本文的Word格式文档,以方便收藏与打印。