欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Java办公信息化管理系统 练习

程序员文章站 2024-03-05 13:03:18
...

编程题目要求

Java办公信息化管理系统 练习
Java办公信息化管理系统 练习
Java办公信息化管理系统 练习

代码展示

package project0717;

/**
 * 部门类
 */
public class Department {
	// 成员属性
	private String departmentID;
	private String departmentName;
	private Staff[] staffs;
	private int staffNumber;

	// get方法
	public String getDepartmentID() {
		return departmentID;
	}

	public String getDepartmentName() {
		return departmentName;
	}

	public Staff[] getStaffs() {
		if (staffs == null) {
			this.staffs = new Staff[10];
		}
		return staffs;
	}

	public int getStaffNumber() {
		return staffNumber;
	}

	// set方法
	public void setDepartmentID(String departmentID) {
		this.departmentID = departmentID;
	}

	public void setDepartmentName(String departmentName) {
		this.departmentName = departmentName;
	}

	public void setStaffs(Staff[] staffs) {
		this.staffs = staffs;
	}

	public void setStaffNumber(int staffNumber) {
		this.staffNumber = staffNumber;
	}

	// 构造器
	public Department() {
		super();
	}

	public Department(String departmentID, String departmentName) {
		super();
		this.setDepartmentID(departmentID);
		this.setDepartmentName(departmentName);
	}

	// 成员方法
	/**
	 * 描述部门信息的方法
	 * 
	 * @return 返回包含部门编号,部门名称和部门人数的字符串
	 */
	public String departmentInfo() {
		String str = "部门编号:" + this.getDepartmentID() + "\n";
		str += "部门名称:" + this.getDepartmentName() + "\n";
		str += "部门人数:" + this.getStaffNumber();
		return str;
	}

	/**
	 * 将员工信息保存到对应部门的数组中
	 * 
	 * @param 实例化的员工对象
	 */
	public void addStaff(Staff staff) {
		int i;
		for (i = 0; i < this.getStaffs().length; i++) {
			if (this.getStaffs()[i] == null) {
				this.getStaffs()[i] = staff;
				break;
			}
		}
		this.setStaffNumber(i + 1);
	}

	/**
	 * 描述部门人数信息的方法
	 * 
	 * @return 返回某个部门人数信息的字符串
	 */
	public String departmentNumberInfo() {
		String str = this.getDepartmentName() + "总共有" + this.getStaffNumber() + "名:";
		for (int i = 0; i < this.getStaffNumber(); i++) {
			str += this.getStaffs()[i].getStaffName() + " ";
		}
		return str;
	}
}

package project0717;

/**
 * 职务类
 */
public class Position {
	// 成员属性
	private String positionID;
	private String positionName;
	private Staff[] positionStaffs;
	private int positionStaffNumber = 0;

	// get方法
	public String getPositionID() {
		return positionID;
	}

	public String getPositionName() {
		return positionName;
	}

	public Staff[] getPositionStaffs() {
		if (positionStaffs == null) {
			positionStaffs = new Staff[10];
		}
		return positionStaffs;
	}

	public int getPositionStaffNumber() {
		return positionStaffNumber;
	}

	// set方法
	public void setPositionID(String positionID) {
		this.positionID = positionID;
	}

	public void setPositionName(String positionName) {
		this.positionName = positionName;
	}

	public void setPositionStaffs(Staff[] positionStaffs) {
		this.positionStaffs = positionStaffs;
	}

	public void setPositionStaffNumber(int positionStaffNumber) {
		this.positionStaffNumber = positionStaffNumber;
	}

	// 构造器
	public Position() {
		super();
	}

	public Position(String positionID, String positionName) {
		super();
		this.positionID = positionID;
		this.positionName = positionName;
	}

	// 成员方法
	/**
	 * 描述职务信息的方法
	 * 
	 * @return 返回包含职务编号和职务名称的字符串
	 */
	public String positionInfo() {
		String str = "职务编号:" + this.getPositionID() + "\n";
		str += "职务名称:" + this.getPositionName();
		return str;
	}

	/**
	 * 将员工信息保存到对应职务的数组中
	 * 
	 * @param 实例化的员工对象
	 */
	public void addPositionStaff(Staff staff) {
		if (this.getPositionStaffNumber() < this.getPositionStaffs().length) {
			this.getPositionStaffs()[getPositionStaffNumber()] = staff;
			this.setPositionStaffNumber(getPositionStaffNumber() + 1);
		} else {
			System.out.println("数据录入失败!");
		}
	}

	/**
	 * 描述职务人数信息的方法
	 * 
	 * @return 返回某个职务人数信息的字符串
	 */
	public String positionNumberInfo() {
		String str = this.getPositionName() + "总共有" + this.getPositionStaffNumber() + "名:";
		for (int i = 0; i < this.getPositionStaffNumber(); i++) {
			str += this.getPositionStaffs()[i].getStaffName() + " ";
		}
		return str;
	}
}

package project0717;

/**
 * 员工类
 */
public class Staff {
	// 成员属性
	private String staffName;
	private String staffID;
	private String staffSex;
	private int staffAge;
	private Department department;
	private Position position;
	// 使用静态变量充当员工总数计数器
	private static int count = 0;

	// get方法
	public String getStaffName() {
		return staffName;
	}

	public String getStaffID() {
		return staffID;
	}

	public String getStaffSex() {
		return staffSex;
	}

	public int getStaffAge() {
		return staffAge;
	}

	public Department getDepartment() {
		if (department == null) {
			this.department = new Department();
		}
		return department;
	}

	public Position getPosition() {
		if (position == null) {
			this.position = new Position();
		}
		return position;
	}

	public static int getCount() {
		return count;
	}

	// set方法
	public void setStaffName(String staffName) {
		this.staffName = staffName;
	}

	public void setStaffID(String staffID) {
		this.staffID = staffID;
	}

	public void setStaffSex(String staffSex) {
		if (staffSex.equals("女")) {
			this.staffSex = "女";
			return;
		}
		this.staffSex = "男";
	}

	public void setStaffAge(int staffAge) {
		if (staffAge > 18 && staffAge <= 65) {
			this.staffAge = staffAge;
			return;
		}
		this.staffAge = 18;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}

	public void setPosition(Position position) {
		this.position = position;
	}

	// 构造器
	public Staff() {
		super();
		count++;
	}

	public Staff(String staffName, String staffID, String staffSex, int staffAge, Department department,
			Position position) {
		super();
		this.setStaffName(staffName);
		this.setStaffID(staffID);
		this.setStaffSex(staffSex);
		this.setStaffAge(staffAge);
		this.setDepartment(department);
		this.setPosition(position);
		// 每次实例化对象 相应的计数
		department.addStaff(this);
		position.addPositionStaff(this);
		count++;
	}

	// 成员方法
	/**
	 * 描述员工信息的方法
	 * 
	 * @return 返回员工姓名,员工工号,员工性别,员工年龄和员工职务的字符串
	 */
	public String staffInfo() {
		String str = "姓名:" + this.getStaffName() + "\n";
		str += "工号:" + this.getStaffID() + "\n";
		str += "性别:" + this.getStaffSex() + "\n";
		str += "年龄:" + this.getStaffAge() + "\n";
		str += "职务:" + this.getDepartment().getDepartmentName() + this.getPosition().getPositionName();
		return str;
	}

	/**
	 * 描述公司总员工数量的方法
	 * 
	 * @return 返回公司员工数量的字符串
	 */
	public static String staffNumberInfo() {
		String str = "本公司共有" + getCount() + "名员工";
		return str;
	}
}

package project0717;

/**
 * 测试类
 */
public class Test {
	public static void horizontalRule() {
		System.out.println("==========================");
	}

	public static void main(String[] args) {
		// 初始化部门
		Department d1 = new Department("D001", "人事部");
		Department d2 = new Department("D002", "市场部");
		// 初始化职务
		Position p1 = new Position("P001", "经理");
		Position p2 = new Position("P002", "助理");
		Position p3 = new Position("P003", "职员");
		// 初始化员工
		Staff s1 = new Staff("张铭", "S001", "男", 29, d1, p1);
		Staff s2 = new Staff("李艾爱", "S002", "女", 21, d1, p2);
		Staff s3 = new Staff("孙超", "S003", "男", 29, d1, p3);
		Staff s4 = new Staff("张美美", "S004", "女", 26, d2, p3);
		Staff s5 = new Staff("蓝迪", "S005", "男", 37, d2, p1);
		Staff s6 = new Staff("米莉", "S006", "女", 24, d2, p3);
		// 输出员工各自信息
		System.out.println(s1.staffInfo());
		horizontalRule();
		System.out.println(s2.staffInfo());
		horizontalRule();
		System.out.println(s3.staffInfo());
		horizontalRule();
		System.out.println(s4.staffInfo());
		horizontalRule();
		System.out.println(s5.staffInfo());
		horizontalRule();
		System.out.println(s6.staffInfo());
		horizontalRule();
		// 输出部门人数汇总信息
		System.out.println(d1.departmentNumberInfo());
		System.out.println(d2.departmentNumberInfo());
		horizontalRule();
		// 输出职务人数汇总信息
		System.out.println(p1.positionNumberInfo());
		System.out.println(p2.positionNumberInfo());
		System.out.println(p3.positionNumberInfo());
		horizontalRule();
		// 输出员工总数信息
		System.out.println(Staff.staffNumberInfo());
	}
}

控制台输出结果

Java办公信息化管理系统 练习

Java办公信息化管理系统 练习