java员工管理系统
时间: 2023-11-20 09:54:57 浏览: 83
Java员工管理系统
Java员工管理系统是一个可以管理员工信息的系统,可以实现员工信息的增删改查等功能。根据提供的引用内容,可以建立一个员工类,包含员工的工号、姓名、年龄、性别和专业属性。同时,可以使用动态数组来存储员工信息,实现对员工信息的管理。
以下是一个简单的Java员工管理系统的示例代码:
```java
import java.util.ArrayList;
import java.util.Scanner;
public class EmployeeManagementSystem {
private ArrayList<Staff> staffList;
public EmployeeManagementSystem() {
staffList = new ArrayList<>();
}
public void addStaff(Staff staff) {
staffList.add(staff);
}
public void deleteStaff(int id) {
for (Staff staff : staffList) {
if (staff.getId() == id) {
staffList.remove(staff);
break;
}
}
}
public void updateStaff(Staff staff) {
for (Staff s : staffList) {
if (s.getId() == staff.getId()) {
s.setName(staff.getName());
s.setAge(staff.getAge());
s.setSex(staff.getSex());
s.setSpecialty(staff.getSpecialty());
break;
}
}
}
public void searchStaff(int id) {
for (Staff staff : staffList) {
if (staff.getId() == id) {
System.out.println(staff);
break;
}
}
}
public void displayAllStaff() {
for (Staff staff : staffList) {
System.out.println(staff);
}
}
public static void main(String[] args) {
EmployeeManagementSystem ems = new EmployeeManagementSystem();
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("请选择操作:1.添加员工 2.删除员工 3.修改员工信息 4.查询员工信息 5.显示所有员工信息 6.退出");
int choice = scanner.nextInt();
switch (choice) {
case 1:
System.out.println("请输入员工信息:");
System.out.print("工号:");
int id = scanner.nextInt();
System.out.print("姓名:");
String name = scanner.next();
System.out.print("年龄:");
int age = scanner.nextInt();
System.out.print("性别:");
String sex = scanner.next();
System.out.print("专业属性:");
String specialty = scanner.next();
Staff staff = new Staff(id, name, age, sex, specialty);
ems.addStaff(staff);
System.out.println("添加成功!");
break;
case 2:
System.out.print("请输入要删除的员工工号:");
int deleteId = scanner.nextInt();
ems.deleteStaff(deleteId);
System.out.println("删除成功!");
break;
case 3:
System.out.println("请输入要修改的员工信息:");
System.out.print("工号:");
int updateId = scanner.nextInt();
System.out.print("姓名:");
String updateName = scanner.next();
System.out.print("年龄:");
int updateAge = scanner.nextInt();
System.out.print("性别:");
String updateSex = scanner.next();
System.out.print("专业属性:");
String updateSpecialty = scanner.next();
Staff updateStaff = new Staff(updateId, updateName, updateAge, updateSex, updateSpecialty);
ems.updateStaff(updateStaff);
System.out.println("修改成功!");
break;
case 4:
System.out.print("请输入要查询的员工工号:");
int searchId = scanner.nextInt();
ems.searchStaff(searchId);
break;
case 5:
ems.displayAllStaff();
break;
case 6:
System.exit(0);
default:
System.out.println("输入有误,请重新输入!");
break;
}
}
}
}
```
阅读全文