import java.util.*;
public class EmpSys {
/*要求 实现对于员工的管理
*
* 1.员工的入职(信息录入)
* 2.员工的离职(删除员工数据)
* 3.员工信息的修改
* 4.员工信息的查询
*
* */
static List<Employee> emps = new ArrayList<>();//声明一个员工集合
static {//初始化的工作
Employee emp1 = new Employee(1, "张三", 18, "女", "12345678900", "123456@qq.com", 5000, 6);
Employee emp2 = new Employee(2, "李四", 20, "女", "12232318900", "123456@qq.com", 6000, 1);
Employee emp3 = new Employee(3, "小红", 16, "女", "12344328900", "1we56@qq.com", 4000, 2);
Employee emp4 = new Employee(4, "小兰", 13, "女", "12363434900", "123qweqwe456@qq.com", 2000, 6);
Employee emp5 = new Employee(5, "小芳", 25, "女", "12365454210", "12qwe56@qq.com", 1000, 5);
Employee emp6 = new Employee(6, "小美", 30, "男", "12369674500", "12qwe56@qq.com", 5500, 4);
Employee emp7 = new Employee(7, "皮蛋", 24, "男", "12324648900", "1234asrg56@qq.com", 4000, 4);
Employee emp8 = new Employee(8, "宝宝", 22, "男", "12345965643", "www456@qq.com", 15000, 9);
Employee emp9 = new Employee(9, "黑妞", 19, "男", "12345672456", "1rrr6@qq.com", 7000, 6);
Employee emp10 = new Employee(10, "亚索", 18, "男", "12345678345", "1222226@qq.com", 400, 10);
emps.add(emp1);
emps.add(emp2);
emps.add(emp3);
emps.add(emp4);
emps.add(emp5);
emps.add(emp6);
emps.add(emp7);
emps.add(emp8);
emps.add(emp9);
emps.add(emp10);
}
static boolean booleans = true;
public static void main(String[] args) {
while (booleans == true) {
System.out.println("🎉🎉🎉🎉🎉🎉🎉-欢迎进入千锋员工系统-🎉🎉🎉🎉🎉🎉🎉");
System.out.println("1.员工入职 2.员工信息修改");
System.out.println("3.员工离职 4.员工信息查询");
System.out.println("5.退出系统 ");
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();//用户输入的选项值
if (i == 1) {
addEmp();
} else if (i == 2) {
setEmp();
} else if (i == 3) {
reMove();
} else if (i == 4) {
search();
} else if (i == 5) {
exit();
} else {
System.out.println("输入有误 ");
}
}
}
private static void search() {
for(int i=0;i<emps.size();i++){
System.out.println(emps.get(i).getId()+emps.get(i).getName());
}
int a=0;
System.out.println("请输入要查询的员工名字");
Scanner sc=new Scanner(System.in);
String name=sc.next();
for(int i=0;i<emps.size();i++) {
if (name.equals(emps.get(i).getName())) {
System.out.println(emps.get(i));
System.out.println("查询成功!!!!");
System.out.println();
System.out.println();
a=1;
}
}
if(a==0){
System.out.println("查无此人");
System.out.println();
System.out.println("---------------------");
}
}
private static void reMove() {
for (int i = 0; i < emps.size(); i++) {
System.out.println(emps.get(i));
}
System.out.println("请选择离职的员工的id");
Scanner sc = new Scanner(System.in);
int id = sc.nextInt();
if (id > 0 && id < emps.size() + 1) {
System.out.println(emps.get(id - 1));
System.out.println("请确认是否是此人离职:是:1 否:2");
Scanner sc1 = new Scanner(System.in);
int a = sc1.nextInt();
if (a == 1) {
emps.remove(id-1);
System.out.println("删除成功!!");
System.out.println();
System.out.println();
System.out.println("-------------------------");
}
}
}
private static void setEmp() {
for(int i=0;i<emps.size();i++ ) {
System.out.println(emps.get(i));
}
// Iterator iterator= emps.iterator();//使用迭代器进行遍历
// while (iterator.hasNext()){
// System.out.println(iterator.next());
// }
System.out.println("请选择要更改信息的员工的id");
Scanner sc=new Scanner(System.in);
int id=sc.nextInt();
if(id>0&&id<emps.size()+1){
System.out.println(emps.get(id-1));
System.out.println("请确认是否要修改此人:是:1 否:2");
Scanner sc1 = new Scanner(System.in);
int a=sc1.nextInt();
if(a==1){
addEmp();
}
}
}
public static void addEmp () {
Integer newId = emps.get(emps.size() - 1).getId() + 1;//新员工的id
Scanner sc = new Scanner(System.in);
System.out.println("请输入员工姓名:");
String name = sc.next();
System.out.println("请输入员工年龄:");
int age = sc.nextInt();
System.out.println("请输入员工性别:");
String gender = sc.next();
System.out.println("请输入员工的电话");
String telephone = sc.next();
System.out.println("请输入员工的邮箱");
String email = sc.next();
System.out.println("请输入员工的工资");
Integer salary = sc.nextInt();
System.out.println("请输入员工的工作时长");
Integer workTime = sc.nextInt();
Employee employee = new Employee();
employee.setId(newId);
employee.setName(name);
employee.setAge(age);
employee.setGender(gender);
employee.setEmail(email);
employee.setSalary(salary);
employee.setTel(telephone);
employee.setWork_time(workTime);
emps.add(employee);
}
public static void add1(int i){
int newId=i;
Scanner sc = new Scanner(System.in);
System.out.println("请输入员工姓名:");
String name = sc.next();
System.out.println("请输入员工年龄:");
int age = sc.nextInt();
System.out.println("请输入员工性别:");
String gender = sc.next();
System.out.println("请输入员工的电话");
String telephone = sc.next();
System.out.println("请输入员工的邮箱");
String email = sc.next();
System.out.println("请输入员工的工资");
Integer salary = sc.nextInt();
System.out.println("请输入员工的工作时长");
Integer workTime = sc.nextInt();
Employee employee = new Employee();
employee.setId(newId);
employee.setName(name);
employee.setAge(age);
employee.setGender(gender);
employee.setEmail(email);
employee.setSalary(salary);
employee.setTel(telephone);
employee.setWork_time(workTime);
emps.add(employee);
emps.remove(i-1);
System.out.println("修改成功!!!");
System.out.println();
System.out.println("-------------------------");
}
private static void exit() {
booleans=false;
System.out.println("-----欢迎下次使用!!!----");
}
}
//请将Employee放在一个新的类中,否则代码报错
public class Employee {
private Integer id;
private String name;
private Integer age;
private String gender;
private String tel;
private String email;
private Integer salary;
private Integer work_time;
public Employee() {
}
public Employee(Integer id, String name, Integer age, String gender, String tel, String email, Integer salary, Integer work_time) {
this.id = id;
this.name = name;
this.age = age;
this.gender = gender;
this.tel = tel;
this.email = email;
this.salary = salary;
this.work_time = work_time;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Integer getSalary() {
return salary;
}
public void setSalary(Integer salary) {
this.salary = salary;
}
public Integer getWork_time() {
return work_time;
}
public void setWork_time(Integer work_time) {
this.work_time = work_time;
}
@Override
public String toString() {//方便查看对象属性
return "Employee{" +
"id=" + id +
", name='" + name + '\'' +
", age=" + age +
", gender='" + gender + '\'' +
", tel='" + tel + '\'' +
", email='" + email + '\'' +
", salary=" + salary +
", work_time='" + work_time + '\'' +
'}';
}
}
【Java】使用Java编写一个员工管理系统。实现增删改查等功能。
于 2022-01-20 09:41:40 首次发布