Java项目--人力信息管理系统

直接上代码吧!
创建了三个类。

1.SystemManage类

import java.util.ArrayList;
import java.util.Scanner;
import java.util.TreeSet;

public class SystemManage {
	Scanner scanner = new Scanner(System.in);
	private String Company_name = "Adfaith Consulting";
	private ArrayList<Employee> employees = new ArrayList<Employee>();

	// 构造函数
	public SystemManage() {
	}

	public SystemManage(ArrayList<Employee> employees) {
		this.employees = employees;
	}

	public SystemManage(String company_name, ArrayList<Employee> employees) {
		super();
		Company_name = company_name;
		this.employees = employees;
	}

	public String getCompany_name() {
		return Company_name;
	}

	public void setCompany_name(String company_name) {
		Company_name = company_name;
	}

	public ArrayList<Employee> getEmployees() {
		return employees;
	}

	public void setEmployees(ArrayList<Employee> employees) {
		this.employees = employees;
	}

	// 菜单
	public void menu() {
		System.out.println(Company_name + "- Employee Information - Main Menu\n"
				+ "=====================================================\n" + "\n" + "1 - Print All Current Records\n"
				+ "2 – Print All Current Records (formatted)\n" + "3 – Print Names and Phone Numbers\n"
				+ "4 – Print Names and Phone Numbers (formatted)\n" + "5 - Search for specific Record(s)\n"
				+ "6 - Add New Records\n" + "7 – Delete Records\n" + "\n" + "Q - Quit\n");
		String choose;
		System.out.print("您的选择:");

		choose = scanner.nextLine();
		if (choose.equals("")) {
			System.out.print("没有输入选择。 按Enter继续...");
			choose = scanner.nextLine();
			System.out.println();
			menu();
		} else {
			switch (choose) {
			case "1":
			case "2":
			case "3":
			case "4":
				display(choose);
				System.out.print("\n按Enter继续...");
				choose = scanner.nextLine();
				System.out.println();
				menu();
				break;
			case "5":
				search();
				choose = scanner.nextLine();
				System.out.println();
				break;
			case "6":
				add();
				choose = scanner.nextLine();
				System.out.println();
				break;
			case "7":
				delete();
				choose = scanner.nextLine();
				System.out.println();
				break;
			case "Q":
				System.out.println("----------------------退出系统----------------------");
				break;
			default:
				System.out.print("代码无效!请按Enter继续...");
				choose = scanner.nextLine();
				System.out.println();
				menu();
				break;
			}
		}
	}

	// 打印
	public void display(String chose) {
		switch (chose) {
		case "1":
			for (Employee e : employees) {
				display1(e);
			}
			break;
		case "2":
			TreeSet<Employee> list = new TreeSet<Employee>(new MyCompare());

			for (Employee e : employees) {
				list.add(e);
			}
			for (Employee e : list) {
				display2(e);
			}
			break;
		case "3":
			for (Employee e : employees) {
				display3(e);
			}
			break;
		case "4":
			for (Employee e : employees) {
				display4(e);
			}
			break;
		default:
			break;
		}
	}

	// ---------------------------------------------------------------
	public void search() {
		String str;
		int flag = 0;
		while (true) {
			System.out.print("输入关键字:");
			str = scanner.nextLine();

			if (str.equals("")) {
				System.out.println("没有输入关键字-请重试!!!");
				continue;
			} else {
				break;
			}
		}
		for (Employee e1 : employees) {
			if (str.equals(e1.getFirstname()) || str.equals(e1.getFirstname().toLowerCase())) {
				display1(e1);
				flag = 1;
			} else if (str.equals(e1.getLastname()) || str.equals(e1.getLastname().toLowerCase())) {
				display1(e1);
				flag = 1;
			} else if (str.equals(e1.getInitial())) {
				display1(e1);
				flag = 1;
			} else if (str.equals(e1.getPayroll_num())) {
				display1(e1);
				flag = 1;
			} else if (str.equals(e1.getTelephone_num())) {
				display1(e1);
				flag = 1;
			} else if (str.equals(e1.getJob_title())) {
				display1(e1);
				flag = 1;
			} else if (str.equals(e1.getDepartment_num())) {
				display1(e1);
				flag = 1;
			} else if (str.equals(e1.getDate_hiring())) {
				display1(e1);
				flag = 1;
			}
		}
		if (flag == 0) {
			System.out.println("找不到" + str + "关键字\n");
		}
		System.out.print("按Enter继续...");
		str = scanner.nextLine();
		menu();
	}
	// search结束--------------------------------------------------------------------

	public void add() {
		Employee e = new Employee();
		System.out.println("Adfaith Consulting –员工记录:\n" + "======================================\n" + "\n"
				+ "员工记录添加:\n" + "\n" + "输入新员工的以下详细信息:\n" + "\n" + "员工3位数的工资单编号\n" + "电话号码\n" + "姓\n" + "名字\n"
				+ "中间初始化\n" + "部门#\n" + "职称\n" + "雇用日期");
		// 工资编号
		String p_num;
		while (true) {
			System.out.print("输入员工的三位数工资单编号:");
			p_num = scanner.nextLine();
			if (e.isPayroll_num(p_num)) {
				e.setPayroll_num(p_num);
				break;
			}
		}
		// 电话号码
		String t_num;
		while (true) {
			System.out.print("输入电话号码(02-12345678):");
			t_num = scanner.nextLine();
			if (e.isTelephone_num(t_num)) {
				e.setTelephone_num(t_num);
				break;
			}

		}
		// 输入姓氏
		String last;
		while (true) {
			System.out.print("输入姓氏:");
			last = scanner.nextLine();
			if (e.isLastname(last)) {
				e.setLastname(last);
				break;
			}
		}
		// 输入名字
		String first;
		while (true) {
			System.out.print("输入名字:");
			first = scanner.nextLine();
			if (e.isFirstname(first)) {
				e.setFirstname(first);
				break;
			}
		}
		// 姓名首字母
		String init;
		while (true) {
			System.out.print("输入中间初始化:");
			init = scanner.nextLine();
			if (e.isInitial(init)) {
				e.setInitial(init);
				break;
			}
		}
		// 输入部门编号
		String dep;
		while (true) {
			System.out.print("输入部门编号:");
			dep = scanner.nextLine();
			if (e.isDepartment_num(dep)) {
				e.setDepartment_num(dep);
				break;
			}
		}
		// 输入职务
		String job;
		while (true) {
			System.out.print("输入职位名称:");
			job = scanner.nextLine();
			if (e.isJob_title(job)) {
				e.setJob_title(job);
				break;
			}
		}
		// 输入雇用日期(dd-mm-yyyy):
		String date;
		while (true) {
			System.out.print("输入雇用日期(dd-mm-yyyy):");
			date = scanner.nextLine();
			if (e.isDate_hiring(date)) {
				e.setDate_hiring(date);
				break;
			}
		}
		employees.add(e);
		System.out.println("--------------------记录已保存--------------------");

		String flag;
		while (true) {
			System.out.print("添加其他员工记录? (y)es或(n)o:");
			flag = scanner.nextLine();
			if (flag.equals("")) {
				System.out.print("没有输入--请再试一次:");
				continue;

			} else {
				if (flag.equals("y")) {
					add();
				} else {
					System.out.println();
					this.menu();
				}
				break;
			}
		}

	}

	// add()结束---------------------------------------------------------------------------------------
	public void delete() {
		// 这要放置个清屏功能
		Employee e = new Employee();
		System.out
				.println("Adfaith Consulting –员工记录:\n" + "======================================\n" + "\n" + "员工记录删除:");
		String num;
		// 判断输入的工资编号num是否存在
		while (true) {
			System.out.print("输入员工的3位数工资编号以启用文件删除:");
			num = scanner.nextLine();
			if (e.isDepartment_num(num)) {
				int t = 0;
				for (Employee employee : employees) {
					if (employee.getPayroll_num().equals(num)) {
						t = 1;
					}
				}
				if (t == 0) {
					System.out.println("员工系统中找不到该工资编号!!!");
					System.out.print("按Enter继续...");
					num = scanner.nextLine();
					menu();
				} else {
					break;
				}
			}
		}

		for (Employee employee : employees) {
			if (employee.getPayroll_num().equals(num)) {
				display1(employee);
				System.out.println();
				break;
			}
		}
		// 删除num
		String flag;
		while (true) {
			System.out.print("确认删除记录(y)es或(n)o:");
			flag = scanner.nextLine();
			if (flag.equals("")) {
				System.out.println("没有输入--再试一次");
				continue;
			} else {
				if (flag.equals("y")) {
					while (true) {
						int t = 0;
						for (Employee e1 : employees) {
							if (e1.getPayroll_num().equals(num)) {
								employees.remove(e1);
								break;
							}
						}
						for (Employee e1 : employees) {
							if (e1.getPayroll_num().equals(num))
								t = 1;
						}
						if (t == 0)
							System.out.println("--------------------记录已删除!--------------------");
						break;
					}
				} else {
					System.out.println("--------------------已取消删除!--------------------");
					menu();
				}

			}
			System.out.print("是否删除另一个? (y)es或(n)o,y(用户输入):");
			String choose = scanner.nextLine();
			if (choose.equals("y")) {
				delete();
			} else {
				System.out.println();
				menu();
				break;
			}
		}

	}
	// delete结束---------------------------------------------------------------------------

	public void Add(Employee e) {
		employees.add(e);
	}

	// 普通打印
	public void display1(Employee e) {
		System.out.println(e.getPayroll_num() + ":" + e.getTelephone_num() + ":" + e.getLastname() + ":"
				+ e.getFirstname() + ":" + e.getInitial() + ":" + e.getDepartment_num() + ":" + e.getJob_title() + ":"
				+ e.getDate_hiring());
	}

	// 格式化打印
	public void display2(Employee e) {
		if (e.getLastname().length() >= 8) {
			System.out.print(e.getLastname() + "\t" + e.getFirstname() + "\t" + e.getInitial() + "\t"
					+ e.getPayroll_num() + "\t" + e.getTelephone_num() + "\t" + e.getDepartment_num() + "\t");
		} else {
			System.out.printf(e.getLastname() + "\t\t" + e.getFirstname() + "\t" + e.getInitial() + "\t"
					+ e.getPayroll_num() + "\t" + e.getTelephone_num() + "\t" + e.getDepartment_num() + "\t");
		}
		if (e.getJob_title().length() >= 16) {
			System.out.println(e.getJob_title() + "\t" + e.getDate_hiring());
		} else if (e.getJob_title().length() >= 8) {
			System.out.println(e.getJob_title() + "\t\t" + e.getDate_hiring());
		} else {
			System.out.println(e.getJob_title() + "\t\t\t" + e.getDate_hiring());
		}
	}

	// 输出名字和电话号码
	public void display3(Employee e) {
		System.out.println(e.getLastname() + "," + e.getFirstname() + "," + e.getTelephone_num());
	}

	// display3的格式化
	public void display4(Employee e) {
		if (e.getLastname().length() >= 8) {
			System.out.println(e.getLastname() + "\t" + e.getFirstname() + "\t" + e.getTelephone_num());
		} else {
			System.out.println(e.getLastname() + "\t\t" + e.getFirstname() + "\t" + e.getTelephone_num());
		}
	}
}

2.Employee类


package com.Project;

import java.text.SimpleDateFormat;

public class Employee {
	private String payroll_num; // 员工工资编号
	private String telephone_num; // 员工电话号码
	private String lastname; // 员工姓氏
	private String firstname; // 员工名字
	private String initial; // 中间初始化
	private String department_num; // 部门编号
	private String job_title; // 员工职称
	private String date_hiring; // 员工录用日期

	public Employee() {
		// TODO Auto-generated constructor stub
	}

	public Employee(String payroll_num, String telephone_num, String lastname, String firstname, String initial,
			String department_num, String job_title, String date_hiring) {
		super();
		this.payroll_num = payroll_num;
		this.telephone_num = telephone_num;
		this.lastname = lastname;
		this.firstname = firstname;
		this.initial = initial;
		this.department_num = department_num;
		this.job_title = job_title;
		this.date_hiring = date_hiring;
	}

	public String getPayroll_num() {
		return payroll_num;
	}

	public void setPayroll_num(String payroll_num) {
		this.payroll_num = payroll_num;
	}

	public String getTelephone_num() {
		return telephone_num;
	}

	public void setTelephone_num(String telephone_num) {
		this.telephone_num = telephone_num;
	}

	public String getLastname() {
		return lastname;
	}

	public void setLastname(String lastname) {
		this.lastname = lastname;
	}

	public String getFirstname() {
		return firstname;
	}

	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}

	public String getInitial() {
		return initial;
	}

	public void setInitial(String initial) {
		this.initial = initial;
	}

	public String getDepartment_num() {
		return department_num;
	}

	public void setDepartment_num(String department_num) {
		this.department_num = department_num;
	}

	public String getJob_title() {
		return job_title;
	}

	public void setJob_title(String job_title) {
		this.job_title = job_title;
	}

	public void setDate_hiring(String date_hiring) {
		this.date_hiring = date_hiring;
	}

	public String getDate_hiring() {
		return date_hiring;
	}

	// 规范输入的数据
	// 工资编号
	public boolean isPayroll_num(String str) {
		if (str.equals("")) {
			System.out.println("没有输入工资单编号--再试一次!!!");
			return false;
		} else {
			for (int i = 0; i < str.length(); i++) {
				if (str.charAt(i) < '0' && str.charAt(i) > '9') {
					System.out.println("工资单编号只能包含数字字符!!!");
					return false;
				}
			}
		}
		return true;
	}

	// 电话号码
	public boolean isTelephone_num(String str) {
		if (str.equals("")) {
			System.out.println("没有输入电话号码--请再试一次!!!!!!");
			return false;
		}

		if (str.charAt(0) != '0' || str.charAt(2) != '-') {
			System.out.println("电话号码无效–-请再试一次!!!!!!");
			return false;
		}
		if (str.charAt(1) == '0' || str.charAt(1) == '1' || str.charAt(1) == '9') {
			System.out.println("电话号码无效–-请再试一次!!!!!!");
			return false;
		}
		if (str.charAt(3) == '0') {
			System.out.println("电话号码无效–-请再试一次!!!!!!");
			return false;
		}
		if (str.length() != 11) {
			System.out.println("电话号码无效–-请再试一次!!!!!!");
			return false;
		}

		for (int i = 0; i < str.length(); i++) {
			if (i == 2)
				continue;
			if (str.charAt(i) < '0' && str.charAt(i) > '9') {
				System.out.println("电话号码无效–-请再试一次!!!!!!");
				return false;
			}
		}

		return true;
	}

	// 姓氏
	public boolean isLastname(String str) {
		if (str.equals("")) {
			System.out.println("没有输入姓氏--请再试一次!!!");
			return false;
		}
		for (int i = 0; i < str.length(); i++) {
			if (str.charAt(i) != ' ' && (str.charAt(i) < 'A' || str.charAt(i) > 'z')) {
				System.out.println("姓名只能包含字母字符和空格!!!");
				return false;
			}
		}

		return true;
	}

	// 名字
	public boolean isFirstname(String str) {
		if (str.equals("")) {
			System.out.println("没有输入名字--请再试一次!!!");
			return false;
		}
		for (int i = 0; i < str.length(); i++) {
			if (str.charAt(i) != ' ' && (str.charAt(i) < 'A' || str.charAt(i) > 'z')) {
				System.out.println("名字只能包含字母字符和空格!!!");
				return false;
			}
		}
		return true;
	}

	// 中间初始化
	public boolean isInitial(String str) {
		if (str.equals("")) {
			System.out.println("没有输入中间初始化--请再试一次!!!");
			return false;
		}
		if (str.length() != 1 && (str.charAt(0) < 'A' || str.charAt(0) > 'z')) {
			System.out.println("中间初始化只能包含一个字母字符和空格!!!");
			return false;
		}

		return true;
	}

	// 部门编号
	public boolean isDepartment_num(String str) {
		if (str.equals("")) {
			System.out.println("没有输入部门编号--请再试一次!!!");
			return false;
		}
		if (str.contains(" ")) {
			System.out.println("部门编号只能包含没有空格的数字!!!");
			return false;
		}
		for (int i = 0; i < str.length(); i++) {
			if ((str.charAt(i) < '0' || str.charAt(i) > '9')) {
				System.out.println("部门编号只能包含没有空格的数字!!!");
				return false;
			}
		}
		return true;
	}

	// 职务
	public boolean isJob_title(String str) {
		if (str.equals("")) {
			System.out.println("没有输入职位名称--请再试一次!!!");
			return false;
		}
		for (int i = 0; i < str.length(); i++) {
			if (str.charAt(i) != ' ' && (str.charAt(i) < 'A' || str.charAt(i) > 'z')) {
				System.out.println("职位名称只能包含字母字符和空格!!!");
				return false;
			}
		}
		return true;
	}

	// 雇佣日期
	public boolean isDate_hiring(String str) {
		if (str.equals("")) {
			System.out.println("没有输入雇用日期--请再试一次!!!");
			return false;
		}
		SimpleDateFormat sd = new SimpleDateFormat("dd-MM-yyyy");
		try {
			sd.setLenient(false);// 关闭容错机制
			sd.parse(str);
		} catch (Exception e) {
			System.out.println("无效的雇用日期!!!");
			return false;
		}
		return true;
	}

}

3.MyCompare类

import java.util.Comparator;
//定制排序
public class MyCompare implements Comparator<Employee> {
	@Override
	public int compare(Employee e1, Employee e2) {
		return e1.getLastname().compareTo(e2.getLastname());
	}
}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

~祝今在

喝个茶水

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值