Java 做一个学生管理系统
时间: 2024-05-12 21:08:28 浏览: 86
一个学生管理系统可以分为以下几个模块:
1. 学生信息管理模块:管理学生的基本信息,包括学号、姓名、性别、出生日期、联系方式、家庭住址等等。
2. 成绩管理模块:管理学生的各科成绩,包括语文、数学、英语、物理、化学、生物等等。
3. 课程管理模块:管理学生所选的课程,包括必修课、选修课、公共选修课等等。
4. 教师管理模块:管理教师的基本信息,包括教师编号、姓名、性别、出生日期、联系方式、授课科目等等。
5. 班级管理模块:管理班级的基本信息,包括班级编号、班级名称、班主任、学生人数等等。
6. 用户管理模块:管理系统中的用户,包括管理员、教师、学生等等。
下面是一个简单的学生管理系统的代码示例:
```
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class StudentManagementSystem {
private static List<Student> studentList = new ArrayList<>();
private static List<Teacher> teacherList = new ArrayList<>();
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("请选择用户类型:");
System.out.println("1. 管理员");
System.out.println("2. 教师");
System.out.println("3. 学生");
System.out.println("4. 退出");
int userType = scanner.nextInt();
switch (userType) {
case 1:
adminLogin(scanner);
break;
case 2:
teacherLogin(scanner);
break;
case 3:
studentLogin(scanner);
break;
case 4:
System.exit(0);
break;
default:
System.out.println("输入错误,请重新输入!");
break;
}
}
}
private static void adminLogin(Scanner scanner) {
System.out.println("请输入管理员用户名:");
String adminName = scanner.next();
System.out.println("请输入管理员密码:");
String adminPassword = scanner.next();
if ("admin".equals(adminName) && "admin".equals(adminPassword)) {
System.out.println("管理员登录成功!");
adminMenu(scanner);
} else {
System.out.println("用户名或密码错误!");
}
}
private static void adminMenu(Scanner scanner) {
while (true) {
System.out.println("请选择操作:");
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("9. 返回上级菜单");
int choice = scanner.nextInt();
switch (choice) {
case 1:
addStudent(scanner);
break;
case 2:
deleteStudent(scanner);
break;
case 3:
modifyStudent(scanner);
break;
case 4:
queryStudent(scanner);
break;
case 5:
addTeacher(scanner);
break;
case 6:
deleteTeacher(scanner);
break;
case 7:
modifyTeacher(scanner);
break;
case 8:
queryTeacher(scanner);
break;
case 9:
return;
default:
System.out.println("输入错误,请重新输入!");
break;
}
}
}
private static void addStudent(Scanner scanner) {
System.out.println("请输入学生学号:");
String studentId = scanner.next();
System.out.println("请输入学生姓名:");
String studentName = scanner.next();
System.out.println("请输入学生性别:");
String studentGender = scanner.next();
System.out.println("请输入学生出生日期:");
String studentBirth = scanner.next();
System.out.println("请输入学生联系方式:");
String studentPhone = scanner.next();
System.out.println("请输入学生家庭住址:");
String studentAddress = scanner.next();
Student student = new Student(studentId, studentName, studentGender, studentBirth, studentPhone, studentAddress);
studentList.add(student);
System.out.println("添加学生成功!");
}
private static void deleteStudent(Scanner scanner) {
System.out.println("请输入要删除的学生学号:");
String studentId = scanner.next();
for (int i = 0; i < studentList.size(); i++) {
if (studentList.get(i).getStudentId().equals(studentId)) {
studentList.remove(i);
System.out.println("删除学生成功!");
return;
}
}
System.out.println("该学号的学生不存在!");
}
private static void modifyStudent(Scanner scanner) {
System.out.println("请输入要修改的学生学号:");
String studentId = scanner.next();
for (int i = 0; i < studentList.size(); i++) {
if (studentList.get(i).getStudentId().equals(studentId)) {
System.out.println("请输入学生姓名:");
String studentName = scanner.next();
System.out.println("请输入学生性别:");
String studentGender = scanner.next();
System.out.println("请输入学生出生日期:");
String studentBirth = scanner.next();
System.out.println("请输入学生联系方式:");
String studentPhone = scanner.next();
System.out.println("请输入学生家庭住址:");
String studentAddress = scanner.next();
studentList.get(i).setStudentName(studentName);
studentList.get(i).setStudentGender(studentGender);
studentList.get(i).setStudentBirth(studentBirth);
studentList.get(i).setStudentPhone(studentPhone);
studentList.get(i).setStudentAddress(studentAddress);
System.out.println("修改学生信息成功!");
return;
}
}
System.out.println("该学号的学生不存在!");
}
private static void queryStudent(Scanner scanner) {
System.out.println("请输入要查询的学生学号:");
String studentId = scanner.next();
for (int i = 0; i < studentList.size(); i++) {
if (studentList.get(i).getStudentId().equals(studentId)) {
System.out.println(studentList.get(i));
return;
}
}
System.out.println("该学号的学生不存在!");
}
private static void addTeacher(Scanner scanner) {
System.out.println("请输入教师编号:");
String teacherId = scanner.next();
System.out.println("请输入教师姓名:");
String teacherName = scanner.next();
System.out.println("请输入教师性别:");
String teacherGender = scanner.next();
System.out.println("请输入教师出生日期:");
String teacherBirth = scanner.next();
System.out.println("请输入教师联系方式:");
String teacherPhone = scanner.next();
System.out.println("请输入授课科目:");
String courseName = scanner.next();
Teacher teacher = new Teacher(teacherId, teacherName, teacherGender, teacherBirth, teacherPhone, courseName);
teacherList.add(teacher);
System.out.println("添加教师成功!");
}
private static void deleteTeacher(Scanner scanner) {
System.out.println("请输入要删除的教师编号:");
String teacherId = scanner.next();
for (int i = 0; i < teacherList.size(); i++) {
if (teacherList.get(i).getTeacherId().equals(teacherId)) {
teacherList.remove(i);
System.out.println("删除教师成功!");
return;
}
}
System.out.println("该编号的教师不存在!");
}
private static void modifyTeacher(Scanner scanner) {
System.out.println("请输入要修改的教师编号:");
String teacherId = scanner.next();
for (int i = 0; i < teacherList.size(); i++) {
if (teacherList.get(i).getTeacherId().equals(teacherId)) {
System.out.println("请输入教师姓名:");
String teacherName = scanner.next();
System.out.println("请输入教师性别:");
String teacherGender = scanner.next();
System.out.println("请输入教师出生日期:");
String teacherBirth = scanner.next();
System.out.println("请输入教师联系方式:");
String teacherPhone = scanner.next();
System.out.println("请输入授课科目:");
String courseName = scanner.next();
teacherList.get(i).setTeacherName(teacherName);
teacherList.get(i).setTeacherGender(teacherGender);
teacherList.get(i).setTeacherBirth(teacherBirth);
teacherList.get(i).setTeacherPhone(teacherPhone);
teacherList.get(i).setCourseName(courseName);
System.out.println("修改教师信息成功!");
return;
}
}
System.out.println("该编号的教师不存在!");
}
private static void queryTeacher(Scanner scanner) {
System.out.println("请输入要查询的教师编号:");
String teacherId = scanner.next();
for (int i = 0; i < teacherList.size(); i++) {
if (teacherList.get(i).getTeacherId().equals(teacherId)) {
System.out.println(teacherList.get(i));
return;
}
}
System.out.println("该编号的教师不存在!");
}
private static void studentLogin(Scanner scanner) {
System.out.println("请输入学生学号:");
String studentId = scanner.next();
for (int i = 0; i < studentList.size(); i++) {
if (studentList.get(i).getStudentId().equals(studentId)) {
System.out.println("学生登录成功!");
studentMenu(scanner, studentList.get(i));
return;
}
}
System.out.println("该学号的学生不存在!");
}
private static void studentMenu(Scanner scanner, Student student) {
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(student);
break;
case 2:
System.out.println("请输入要查询的科目:");
String courseName = scanner.next();
System.out.println("成绩为:" + student.getScore(courseName));
break;
case 3:
System.out.println("已选课程为:" + student.getCourseList());
break;
case 4:
return;
default:
System.out.println("输入错误,请重新输入!");
break;
}
}
}
private static void teacherLogin(Scanner scanner) {
System.out.println("请输入教师编号:");
String teacherId = scanner.next();
for (int i = 0; i < teacherList.size(); i++) {
if (teacherList.get(i).getTeacherId().equals(teacherId)) {
System.out.println("教师登录成功!");
teacherMenu(scanner, teacherList.get(i));
return;
}
}
System.out.println("该编号的教师不存在!");
}
private static void teacherMenu(Scanner scanner, Teacher teacher) {
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(teacher);
break;
case 2:
System.out.println("授课科目为:" + teacher.getCourseName());
System.out.println("所授班级为:" + teacher.getClassList());
break;
case 3:
System.out.println("请输入要修改成绩的学生学号:");
String studentId = scanner.next();
for (Student student : studentList) {
if (student.getStudentId().equals(studentId)) {
System.out.println("请输入要修改的科目:");
String courseName = scanner.next();
System.out.println("请输入新的成绩:");
int score = scanner.nextInt();
student.setScore(courseName, score);
System.out.println("修改成绩成功!");
return;
}
}
System.out.println("该学号的学生不存在!");
break;
case 4:
return;
default:
System.out.println("输入错误,请重新输入!");
break;
}
}
}
}
```
该系统包含了管理员、教师和学生三种用户类型,具有添加、删除、修改和查询学生、教师、课程和成绩等功能。在实际应用中,还可以根据需要增加其他功能模块。
阅读全文