用java写一个信息管理系统
时间: 2023-07-18 19:29:05 浏览: 44
好的,下面给您提供一个简单的 Java 信息管理系统示例代码:
```java
import java.util.ArrayList;
import java.util.Scanner;
public class StudentInfoSystem {
private ArrayList<Student> students;
public StudentInfoSystem() {
students = new ArrayList<Student>();
}
public void addStudent(Student student) {
students.add(student);
}
public void removeStudent(int index) {
students.remove(index);
}
public void displayAllStudents() {
if(students.size() == 0) {
System.out.println("没有学生信息!");
} else {
for(int i=0; i<students.size(); i++) {
System.out.println(students.get(i));
}
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
StudentInfoSystem system = new StudentInfoSystem();
while(true) {
System.out.println("请输入操作序号:");
System.out.println("1. 添加学生信息");
System.out.println("2. 删除学生信息");
System.out.println("3. 显示所有学生信息");
System.out.println("4. 退出程序");
int choice = scanner.nextInt();
switch(choice) {
case 1:
System.out.println("请输入学生姓名:");
String name = scanner.next();
System.out.println("请输入学生年龄:");
int age = scanner.nextInt();
System.out.println("请输入学生性别:");
String gender = scanner.next();
Student student = new Student(name, age, gender);
system.addStudent(student);
System.out.println("学生信息添加成功!");
break;
case 2:
if(system.students.size() == 0) {
System.out.println("没有学生信息!");
} else {
System.out.println("请选择要删除的学生序号:");
for(int i=0; i<system.students.size(); i++) {
System.out.println(i + ". " + system.students.get(i).getName());
}
int index = scanner.nextInt();
system.removeStudent(index);
System.out.println("学生信息删除成功!");
}
break;
case 3:
system.displayAllStudents();
break;
case 4:
System.exit(0);
default:
System.out.println("输入有误,请重新输入!");
}
}
}
}
class Student {
private String name;
private int age;
private String gender;
public Student(String name, int age, String gender) {
this.name = name;
this.age = age;
this.gender = gender;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
public String getGender() {
return gender;
}
public String toString() {
return "姓名:" + name + ",年龄:" + age + ",性别:" + gender;
}
}
```
这个信息管理系统可以实现添加、删除和显示学生信息的功能,您可以根据自己的需要进行修改和完善。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)