生成一段java的管理系统
时间: 2023-03-15 14:07:48 浏览: 61
下面是一段简单的 Java 代码,实现了一个员工管理系统:
```
import java.util.Scanner;
class Employee {
private String name;
private int age;
private String department;
public Employee(String name, int age, String department) {
this.name = name;
this.age = age;
this.department = department;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
public String getDepartment() {
return department;
}
}
public class EmployeeManager {
private static Employee[] employees = new Employee[100];
private static int employeeCount = 0;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("1. 添加员工");
System.out.println("2. 显示员工列表");
System.out.println("3. 退出系统");
System.out.print("请选择操作:");
int choice = scanner.nextInt();
if (choice == 1) {
addEmployee();
} else if (choice == 2) {
showEmployeeList();
} else if (choice == 3) {
break;
} else {
System.out.println("输入有误,请重新输入!");
}
}
System.out.println("退出系统");
}
private static void addEmployee() {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入员工姓名:");
String name = scanner.nextLine();
System.out.print("请输入员工年龄:");
int age = scanner.nextInt();
System.out.print("请输入员工部门:");
String department = scanner.nextLine();
employees[employeeCount++] = new Employee(name, age, department);
System.out.println("添加成功!");
}
private static void showEmployeeList() {
System.out.println("员工列表:");
for (int i = 0; i < employeeCount; i++) {
Employee employee = employees[i];
System.out.println("姓名:" + employee.getName() + ",年龄:" + employee.getAge() + ",部门:" + employee.
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![xlsx](https://img-home.csdnimg.cn/images/20210720083732.png)