用Java代码写一个简单的管理系统
时间: 2023-02-19 12:02:32 浏览: 60
下面是一个使用 Java 编写的简单管理系统的示例代码:
```
import java.util.Scanner;
public class ManagementSystem {
public static void main(String[] args) {
// 创建一个存储员工信息的数组
Employee[] employees = new Employee[10];
// 创建一个 Scanner 对象用于读取输入
Scanner scanner = new Scanner(System.in);
// 循环提示用户进行操作,直到用户输入 "exit" 为止
while (true) {
System.out.println("请输入操作(add/list/exit):");
String operation = scanner.nextLine();
if (operation.equals("add")) {
// 添加员工
System.out.println("请输入员工信息(格式:姓名, 工号, 工资):");
String employeeInfo = scanner.nextLine();
String[] employeeInfoArray = employeeInfo.split(",");
String name = employeeInfoArray[0];
int id = Integer.parseInt(employeeInfoArray[1]);
double salary = Double.parseDouble(employeeInfoArray[2]);
// 创建员工对象并添加到数组中
Employee employee = new Employee(name, id, salary);
for (int i = 0; i < employees.length; i++) {
if (employees[i] == null) {
employees[i] = employee;
break;
}
}
} else if (operation.equals("list")) {
// 列出所有员工信息
for (int i = 0; i < employees.length; i++) {
if (employees[i] != null) {
System.out.println(employees[i]);
}
}
} else if (operation.equals("exit")) {
// 退出系统
break;
} else {
// 无效操作
System.out.println("无效操作");
}
}
// 关闭 Scanner 对象
scanner.close();
}
}
// 员工类
class Employee {
private String name;
private int id;
private double salary;
public Employee(String name, int id, double salary) {
this.name = name;
this.id =
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)