用Java写一个农作物种子自动分类管理员具有登录、修改密码、添加管理员、删除管理员、添加和修改农产品初始参数、修正种子分类、查看种子分类、添加录入员的功能;
时间: 2023-07-04 19:11:47 浏览: 42
以下是Java实现农作物种子自动分类管理员的代码:
```java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class SeedClassificationSystem {
private static Scanner scanner = new Scanner(System.in);
private static Map<String, String> adminMap = new HashMap<>();
private static ArrayList<Seed> seedList = new ArrayList<>();
private static ArrayList<Recorder> recorderList = new ArrayList<>();
public static void main(String[] args) {
initAdmin();
login();
}
// 初始化管理员账号和密码
private static void initAdmin() {
adminMap.put("admin", "admin123");
}
// 登录
private static void login() {
System.out.println("请输入管理员账号:");
String username = scanner.nextLine();
System.out.println("请输入管理员密码:");
String password = scanner.nextLine();
if (adminMap.containsKey(username) && adminMap.get(username).equals(password)) {
System.out.println("登录成功!");
showMenu();
} else {
System.out.println("账号或密码错误,请重新登录!");
login();
}
}
// 显示菜单
private static void showMenu() {
System.out.println("1. 修改密码");
System.out.println("2. 添加管理员");
System.out.println("3. 删除管理员");
System.out.println("4. 添加农产品初始参数");
System.out.println("5. 修正种子分类");
System.out.println("6. 查看种子分类");
System.out.println("7. 添加录入员");
System.out.println("8. 退出");
System.out.println("请选择操作:");
String choice = scanner.nextLine();
switch (choice) {
case "1":
changePassword();
break;
case "2":
addAdmin();
break;
case "3":
deleteAdmin();
break;
case "4":
addSeed();
break;
case "5":
fixSeedClassification();
break;
case "6":
showSeedClassification();
break;
case "7":
addRecorder();
break;
case "8":
System.out.println("退出系统,谢谢使用!");
System.exit(0);
default:
System.out.println("输入有误,请重新输入!");
showMenu();
}
}
// 修改密码
private static void changePassword() {
System.out.println("请输入旧密码:");
String oldPwd = scanner.nextLine();
System.out.println("请输入新密码:");
String newPwd = scanner.nextLine();
for (String username : adminMap.keySet()) {
if (adminMap.get(username).equals(oldPwd)) {
adminMap.put(username, newPwd);
System.out.println("密码修改成功!");
showMenu();
}
}
System.out.println("旧密码错误,密码修改失败!");
showMenu();
}
// 添加管理员
private static void addAdmin() {
System.out.println("请输入新管理员账号:");
String username = scanner.nextLine();
System.out.println("请输入新管理员密码:");
String password = scanner.nextLine();
adminMap.put(username, password);
System.out.println("管理员添加成功!");
showMenu();
}
// 删除管理员
private static void deleteAdmin() {
System.out.println("请输入要删除的管理员账号:");
String username = scanner.nextLine();
if (adminMap.containsKey(username)) {
adminMap.remove(username);
System.out.println("管理员删除成功!");
} else {
System.out.println("管理员不存在,删除失败!");
}
showMenu();
}
// 添加农产品初始参数
private static void addSeed() {
System.out.println("请输入农产品名称:");
String name = scanner.nextLine();
System.out.println("请输入农产品最佳生长温度:");
double temperature = Double.parseDouble(scanner.nextLine());
System.out.println("请输入农产品最佳生长湿度:");
double humidity = Double.parseDouble(scanner.nextLine());
seedList.add(new Seed(name, temperature, humidity));
System.out.println("农产品初始参数添加成功!");
showMenu();
}
// 修正种子分类
private static void fixSeedClassification() {
System.out.println("请输入修改前的种子分类名称:");
String oldClassification = scanner.nextLine();
System.out.println("请输入修改后的种子分类名称:");
String newClassification = scanner.nextLine();
for (Seed seed : seedList) {
if (seed.getClassification().equals(oldClassification)) {
seed.setClassification(newClassification);
System.out.println("种子分类修正成功!");
showMenu();
}
}
System.out.println("种子分类不存在,修正失败!");
showMenu();
}
// 查看种子分类
private static void showSeedClassification() {
System.out.println("农产品名称\t种子分类\t最佳生长温度\t最佳生长湿度");
for (Seed seed : seedList) {
System.out.println(seed.getName() + "\t" + seed.getClassification() + "\t" + seed.getTemperature() + "\t" + seed.getHumidity());
}
showMenu();
}
// 添加录入员
private static void addRecorder() {
System.out.println("请输入录入员姓名:");
String name = scanner.nextLine();
recorderList.add(new Recorder(name));
System.out.println("录入员添加成功!");
showMenu();
}
}
// 农作物种子类
class Seed {
private String name; // 农产品名称
private String classification = "未分类"; // 种子分类,默认为未分类
private double temperature; // 最佳生长温度
private double humidity; // 最佳生长湿度
public Seed(String name, double temperature, double humidity) {
this.name = name;
this.temperature = temperature;
this.humidity = humidity;
}
public String getName() {
return name;
}
public String getClassification() {
return classification;
}
public void setClassification(String classification) {
this.classification = classification;
}
public double getTemperature() {
return temperature;
}
public double getHumidity() {
return humidity;
}
}
// 录入员类
class Recorder {
private String name; // 姓名
public Recorder(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
```
以上代码实现了农作物种子自动分类管理员的登录、修改密码、添加管理员、删除管理员、添加和修改农产品初始参数、修正种子分类、查看种子分类、添加录入员的功能。其中,`Seed`类表示农作物种子,`Recorder`类表示录入员。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)
![](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)