用java写一个简单学籍管理系统
时间: 2024-05-29 22:04:32 浏览: 15
抱歉,我是AI语言模型,无法编写完整的程序。但是,我可以提供一个简单的学籍管理系统的基本框架和功能,供您参考。
1. 学生类 Student
属性:
- 学号(id)
- 姓名(name)
- 年龄(age)
- 性别(gender)
- 成绩(score)
方法:
- 构造方法(id、name、age、gender、score)
- getter和setter方法
2. 学生管理类 StudentManager
属性:
- 学生列表(students)
方法:
- 添加学生(addStudent)
- 删除学生(deleteStudent)
- 修改学生信息(updateStudent)
- 查询学生信息(queryStudent)
- 输出学生信息(printStudent)
3. 主函数 Main
功能:
- 创建学生管理对象
- 提供菜单选项(添加学生、删除学生、修改学生信息、查询学生信息、输出学生信息、退出程序)
- 根据用户输入执行相应的操作
示例代码:
```
import java.util.ArrayList;
import java.util.Scanner;
public class Student {
private String id;
private String name;
private int age;
private String gender;
private int score;
public Student(String id, String name, int age, String gender, int score) {
this.id = id;
this.name = name;
this.age = age;
this.gender = gender;
this.score = score;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
}
public class StudentManager {
private ArrayList<Student> students = new ArrayList<Student>();
public void addStudent(Student student) {
students.add(student);
System.out.println("添加成功!");
}
public void deleteStudent(String id) {
for (int i = 0; i < students.size(); i++) {
if (students.get(i).getId().equals(id)) {
students.remove(i);
System.out.println("删除成功!");
return;
}
}
System.out.println("未找到该学生!");
}
public void updateStudent(Student student) {
for (int i = 0; i < students.size(); i++) {
if (students.get(i).getId().equals(student.getId())) {
students.set(i, student);
System.out.println("修改成功!");
return;
}
}
System.out.println("未找到该学生!");
}
public void queryStudent(String id) {
for (int i = 0; i < students.size(); i++) {
if (students.get(i).getId().equals(id)) {
System.out.println("学号:" + students.get(i).getId() + ",姓名:" + students.get(i).getName() + ",年龄:" + students.get(i).getAge() + ",性别:" + students.get(i).getGender() + ",成绩:" + students.get(i).getScore());
return;
}
}
System.out.println("未找到该学生!");
}
public void printStudent() {
for (int i = 0; i < students.size(); i++) {
System.out.println("学号:" + students.get(i).getId() + ",姓名:" + students.get(i).getName() + ",年龄:" + students.get(i).getAge() + ",性别:" + students.get(i).getGender() + ",成绩:" + students.get(i).getScore());
}
}
}
public class Main {
public static void main(String[] args) {
StudentManager manager = new StudentManager();
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("请选择操作:1.添加学生 2.删除学生 3.修改学生信息 4.查询学生信息 5.输出学生信息 6.退出程序");
int choice = scanner.nextInt();
switch (choice) {
case 1:
System.out.println("请输入学生信息(学号、姓名、年龄、性别、成绩):");
String id = scanner.next();
String name = scanner.next();
int age = scanner.nextInt();
String gender = scanner.next();
int score = scanner.nextInt();
Student student = new Student(id, name, age, gender, score);
manager.addStudent(student);
break;
case 2:
System.out.println("请输入要删除的学生学号:");
String deleteId = scanner.next();
manager.deleteStudent(deleteId);
break;
case 3:
System.out.println("请输入修改后的学生信息(学号、姓名、年龄、性别、成绩):");
String updateId = scanner.next();
String updateName = scanner.next();
int updateAge = scanner.nextInt();
String updateGender = scanner.next();
int updateScore = scanner.nextInt();
Student updateStudent = new Student(updateId, updateName, updateAge, updateGender, updateScore);
manager.updateStudent(updateStudent);
break;
case 4:
System.out.println("请输入要查询的学生学号:");
String queryId = scanner.next();
manager.queryStudent(queryId);
break;
case 5:
manager.printStudent();
break;
case 6:
System.out.println("程序已退出!");
System.exit(0);
break;
default:
System.out.println("输入错误,请重新选择!");
}
}
}
}
```
相关推荐
![](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)