1.对象数组: 日.创建员工 (Emp loyee)类,里面有员工姓名、性别、年龄、所 在部门、职务属性;打印自身信息方法 b.业务需求:员工管理系统, 1--员工添加 2----员工查询 要求可以楯环使用
时间: 2023-12-03 19:46:35 浏览: 152
emp.rar_emp .mvc_mvc员工管理_用mvc员工申请
下面是一个简单的员工管理系统代码实现:
```java
import java.util.Scanner;
public class EmployeeManagementSystem {
private static final int MAX_EMPLOYEES = 100; // 最大员工数
private Employee[] employees = new Employee[MAX_EMPLOYEES]; // 员工数组
private int employeeCount = 0; // 当前员工数
public static void main(String[] args) {
EmployeeManagementSystem system = new EmployeeManagementSystem();
system.run();
}
// 运行员工管理系统
public void run() {
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("请选择操作:");
System.out.println("1. 添加员工");
System.out.println("2. 查询员工");
System.out.println("3. 退出系统");
int choice = scanner.nextInt();
switch (choice) {
case 1:
addEmployee(scanner);
break;
case 2:
searchEmployee(scanner);
break;
case 3:
System.exit(0);
break;
default:
System.out.println("无效操作,请重新选择!");
break;
}
}
}
// 添加员工
private void addEmployee(Scanner scanner) {
if (employeeCount >= MAX_EMPLOYEES) {
System.out.println("员工已满,无法添加!");
return;
}
System.out.println("请输入员工姓名:");
String name = scanner.next();
System.out.println("请输入员工性别:");
String gender = scanner.next();
System.out.println("请输入员工年龄:");
int age = scanner.nextInt();
System.out.println("请输入员工所在部门:");
String department = scanner.next();
System.out.println("请输入员工职务:");
String position = scanner.next();
Employee employee = new Employee(name, gender, age, department, position);
employees[employeeCount++] = employee;
System.out.println("添加员工成功!");
}
// 查询员工
private void searchEmployee(Scanner scanner) {
System.out.println("请输入要查询的员工姓名:");
String name = scanner.next();
for (int i = 0; i < employeeCount; i++) {
if (employees[i].getName().equals(name)) {
System.out.println("员工姓名:" + employees[i].getName());
System.out.println("员工性别:" + employees[i].getGender());
System.out.println("员工年龄:" + employees[i].getAge());
System.out.println("员工所在部门:" + employees[i].getDepartment());
System.out.println("员工职务:" + employees[i].getPosition());
return;
}
}
System.out.println("没有找到该员工!");
}
// 员工类
private static class Employee {
private String name; // 姓名
private String gender; // 性别
private int age; // 年龄
private String department; // 部门
private String position; // 职务
public Employee(String name, String gender, int age, String department, String position) {
this.name = name;
this.gender = gender;
this.age = age;
this.department = department;
this.position = position;
}
public String getName() {
return name;
}
public String getGender() {
return gender;
}
public int getAge() {
return age;
}
public String getDepartment() {
return department;
}
public String getPosition() {
return position;
}
}
}
```
该程序中,定义了一个 `Employee` 类,表示员工,包含员工姓名、性别、年龄、所在部门、职务属性,并且提供了打印自身信息方法。另外,还定义了一个 `EmployeeManagementSystem` 类,该类表示员工管理系统,包含员工数组、当前员工数等属性,并提供了运行员工管理系统、添加员工、查询员工等方法。通过这些方法,可以实现对员工的添加和查询操作。
阅读全文