用java语言编写一个学生选课管理系统的代码。要求1,实现课程信息打印、查询、录入、删除、修改功能。 2,实现学生信息打印、查询、录入、删除、修改功能。 管理端系统设置。仿真加密系统,实现密码防护、修改密码、注销功能。其中密码防护功能实现用户多次输入密码错误,系统将进入休眠状态,等待一段时间后用户才能重新输入密码,防止用户恶意登录。
时间: 2024-03-10 18:51:20 浏览: 23
好的,下面是一个简单的学生选课管理系统代码,满足您的要求:
```
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
public class Course {
private String courseCode; // 课程代码
private String courseName; // 课程名称
private String teacher; // 授课教师
private int credit; // 学分
public Course(String courseCode, String courseName, String teacher, int credit) {
this.courseCode = courseCode;
this.courseName = courseName;
this.teacher = teacher;
this.credit = credit;
}
public String getCourseCode() {
return courseCode;
}
public void setCourseCode(String courseCode) {
this.courseCode = courseCode;
}
public String getCourseName() {
return courseName;
}
public void setCourseName(String courseName) {
this.courseName = courseName;
}
public String getTeacher() {
return teacher;
}
public void setTeacher(String teacher) {
this.teacher = teacher;
}
public int getCredit() {
return credit;
}
public void setCredit(int credit) {
this.credit = credit;
}
}
class Student {
private String studentID; // 学生学号
private String name; // 学生姓名
private int credit; // 已修学分
private List<Course> selectedCourses; // 已选课程
public Student(String studentID, String name) {
this.studentID = studentID;
this.name = name;
this.credit = 0;
selectedCourses = new ArrayList<Course>();
}
public String getStudentID() {
return studentID;
}
public void setStudentID(String studentID) {
this.studentID = studentID;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getCredit() {
return credit;
}
public void setCredit(int credit) {
this.credit = credit;
}
public List<Course> getSelectedCourses() {
return selectedCourses;
}
public void setSelectedCourses(List<Course> selectedCourses) {
this.selectedCourses = selectedCourses;
}
}
class CourseManager {
private List<Course> courseList; // 课程列表
public CourseManager() {
courseList = new ArrayList<Course>();
}
public void printCourses() {
System.out.println("课程列表:");
for (Course course : courseList) {
System.out.println(course.getCourseCode() + " " + course.getCourseName() + " " + course.getTeacher() + " "
+ course.getCredit());
}
}
public Course findCourse(String courseCode) {
for (Course course : courseList) {
if (course.getCourseCode().equals(courseCode)) {
return course;
}
}
return null;
}
public void addCourse() {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入课程代码:");
String courseCode = scanner.nextLine();
System.out.print("请输入课程名称:");
String courseName = scanner.nextLine();
System.out.print("请输入授课教师:");
String teacher = scanner.nextLine();
System.out.print("请输入学分:");
int credit = scanner.nextInt();
scanner.nextLine();
Course course = new Course(courseCode, courseName, teacher, credit);
courseList.add(course);
System.out.println("添加课程成功!");
}
public void deleteCourse() {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入要删除的课程代码:");
String courseCode = scanner.nextLine();
Course course = findCourse(courseCode);
if (course != null) {
courseList.remove(course);
System.out.println("删除课程成功!");
} else {
System.out.println("没有找到该课程!");
}
}
public void modifyCourse() {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入要修改的课程代码:");
String courseCode = scanner.nextLine();
Course course = findCourse(courseCode);
if (course != null) {
System.out.print("请输入新的课程名称(原名称:" + course.getCourseName() + "):");
String courseName = scanner.nextLine();
System.out.print("请输入新的授课教师(原教师:" + course.getTeacher() + "):");
String teacher = scanner.nextLine();
System.out.print("请输入新的学分(原学分:" + course.getCredit() + "):");
int credit = scanner.nextInt();
scanner.nextLine();
course.setCourseName(courseName);
course.setTeacher(teacher);
course.setCredit(credit);
System.out.println("修改课程成功!");
} else {
System.out.println("没有找到该课程!");
}
}
}
class StudentManager {
private List<Student> studentList; // 学生列表
private CourseManager courseManager; // 课程管理器
public StudentManager() {
studentList = new ArrayList<Student>();
courseManager = new CourseManager();
}
public void printStudents() {
System.out.println("学生列表:");
for (Student student : studentList) {
System.out.println(student.getStudentID() + " " + student.getName() + " " + student.getCredit());
System.out.println("已选课程:");
for (Course course : student.getSelectedCourses()) {
System.out.println(course.getCourseCode() + " " + course.getCourseName() + " " + course.getTeacher()
+ " " + course.getCredit());
}
}
}
public Student findStudent(String studentID) {
for (Student student : studentList) {
if (student.getStudentID().equals(studentID)) {
return student;
}
}
return null;
}
public void addStudent() {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入学生学号:");
String studentID = scanner.nextLine();
System.out.print("请输入学生姓名:");
String name = scanner.nextLine();
Student student = new Student(studentID, name);
studentList.add(student);
System.out.println("添加学生成功!");
}
public void deleteStudent() {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入要删除的学生学号:");
String studentID = scanner.nextLine();
Student student = findStudent(studentID);
if (student != null) {
studentList.remove(student);
System.out.println("删除学生成功!");
} else {
System.out.println("没有找到该学生!");
}
}
public void modifyStudent() {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入要修改的学生学号:");
String studentID = scanner.nextLine();
Student student = findStudent(studentID);
if (student != null) {
System.out.print("请输入新的学生姓名(原姓名:" + student.getName() + "):");
String name = scanner.nextLine();
student.setName(name);
System.out.println("修改学生成功!");
} else {
System.out.println("没有找到该学生!");
}
}
public void selectCourse() {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入学生学号:");
String studentID = scanner.nextLine();
Student student = findStudent(studentID);
if (student == null) {
System.out.println("没有找到该学生!");
return;
}
System.out.println("该学生已选课程:");
for (Course course : student.getSelectedCourses()) {
System.out.println(course.getCourseCode() + " " + course.getCourseName() + " " + course.getTeacher()
+ " " + course.getCredit());
}
System.out.println("可选课程列表:");
courseManager.printCourses();
System.out.print("请输入要选修的课程代码:");
String courseCode = scanner.nextLine();
Course course = courseManager.findCourse(courseCode);
if (course == null) {
System.out.println("没有找到该课程!");
return;
}
if (student.getCredit() + course.getCredit() > 20) {
System.out.println("学分已超过上限,不能选修该课程!");
return;
}
student.getSelectedCourses().add(course);
student.setCredit(student.getCredit() + course.getCredit());
System.out.println("选课成功!");
}
public void dropCourse() {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入学生学号:");
String studentID = scanner.nextLine();
Student student = findStudent(studentID);
if (student == null) {
System.out.println("没有找到该学生!");
return;
}
System.out.println("该学生已选课程:");
for (int i = 0; i < student.getSelectedCourses().size(); i++) {
Course course = student.getSelectedCourses().get(i);
System.out.println((i + 1) + ". " + course.getCourseCode() + " " + course.getCourseName() + " "
+ course.getTeacher() + " " + course.getCredit());
}
System.out.print("请输入要退选的课程编号:");
int index = scanner.nextInt() - 1;
scanner.nextLine();
if (index < 0 || index >= student.getSelectedCourses().size()) {
System.out.println("输入有误!");
return;
}
Course course = student.getSelectedCourses().get(index);
student.getSelectedCourses().remove(index);
student.setCredit(student.getCredit() - course.getCredit());
System.out.println("退课成功!");
}
}
class SecurityManager {
private Map<String, String> userMap; // 用户名和密码映射表
private Map<String, Integer> attemptMap; // 用户名和尝试次数映射表
private static final int MAX_ATTEMPTS = 3; // 最大尝试次数
private static final long SLEEP_TIME = 5000; // 休眠时间(毫秒)
public SecurityManager() {
userMap = new HashMap<String, String>();
attemptMap = new HashMap<String, Integer>();
}
public void addUser(String username, String password) {
userMap.put(username, password);
}
public void deleteUser(String username) {
userMap.remove(username);
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)