利用java代码:系统至少应包括以下信息: 学生信息:学号、姓名、性别、年级、密码 课程信息:课程编号、课程名称、已选人数、可选人数、授课教师。 (1) 文件CourseDB.java:单例类,模拟数据库中的课程,初始化后至少封装10门课程; (2)文件StudentDB.java:单列类,模拟数据库中的课程,初始化后至少封装5名学生信息; (3)文件Login.java:负责登录的业务逻辑; (4)文件SelectCourse.java:负责选课的业务逻辑; (5)文件MainProcess.java:负责整体业务流程; (6)学生选课成功后,选课状态变更为“已选”,否则,课程状态变更为“可选”;学生选择“已选”课程,提示“该课程无法重复选择”; (7)学生选课成功后,选课人数相应发生变化;
时间: 2024-02-20 10:59:08 浏览: 74
学生信息管理系统java课程设计(含源代码)
5星 · 资源好评率100%
好的,以下是利用Java代码实现上述系统的示例:
CourseDB.java
```java
import java.util.ArrayList;
import java.util.List;
public class CourseDB {
private static CourseDB instance;
private List<Course> courses;
private CourseDB() {
courses = new ArrayList<>();
courses.add(new Course("C001", "Java基础", 0, 2, "张三"));
courses.add(new Course("C002", "Java高级", 0, 3, "李四"));
courses.add(new Course("C003", "数据库基础", 0, 2, "王五"));
courses.add(new Course("C004", "操作系统", 0, 2, "赵六"));
courses.add(new Course("C005", "计算机网络", 0, 2, "钱七"));
courses.add(new Course("C006", "数据结构与算法", 0, 2, "孙八"));
courses.add(new Course("C007", "软件工程", 0, 2, "周九"));
courses.add(new Course("C008", "人工智能", 0, 2, "吴十"));
courses.add(new Course("C009", "计算机组成原理", 0, 2, "郑一"));
courses.add(new Course("C010", "编译原理", 0, 2, "钱二"));
}
public static CourseDB getInstance() {
if (instance == null) {
instance = new CourseDB();
}
return instance;
}
public List<Course> getCourses() {
return courses;
}
public void setCourses(List<Course> courses) {
this.courses = courses;
}
}
```
StudentDB.java
```java
import java.util.ArrayList;
import java.util.List;
public class StudentDB {
private static StudentDB instance;
private List<Student> students;
private StudentDB() {
students = new ArrayList<>();
students.add(new Student("S001", "张三", "男", "大一", "123456"));
students.add(new Student("S002", "李四", "女", "大一", "234567"));
students.add(new Student("S003", "王五", "男", "大二", "345678"));
students.add(new Student("S004", "赵六", "女", "大二", "456789"));
students.add(new Student("S005", "钱七", "男", "大三", "567890"));
}
public static StudentDB getInstance() {
if (instance == null) {
instance = new StudentDB();
}
return instance;
}
public List<Student> getStudents() {
return students;
}
public void setStudents(List<Student> students) {
this.students = students;
}
}
```
Login.java
```java
import java.util.Scanner;
public class Login {
public static Student login() {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入学号:");
String id = scanner.nextLine();
System.out.println("请输入密码:");
String password = scanner.nextLine();
for (Student student : StudentDB.getInstance().getStudents()) {
if (student.getId().equals(id) && student.getPassword().equals(password)) {
System.out.println("登录成功!");
return student;
}
}
System.out.println("学号或密码错误,请重新输入!");
return null;
}
}
```
SelectCourse.java
```java
import java.util.Scanner;
public class SelectCourse {
public static void selectCourse(Student student) {
Scanner scanner = new Scanner(System.in);
System.out.println("请选择要选的课程编号:");
String courseId = scanner.nextLine();
for (Course course : CourseDB.getInstance().getCourses()) {
if (course.getId().equals(courseId)) {
if (course.getSelectedNum() < course.getLimitNum()) {
if (student.getSelectedCourses().contains(course)) {
System.out.println("该课程已经选择过了!");
} else {
student.getSelectedCourses().add(course);
course.setSelectedNum(course.getSelectedNum() + 1);
System.out.println("选课成功!");
}
} else {
System.out.println("该课程已经选满!");
}
return;
}
}
System.out.println("没有找到该课程!");
}
}
```
MainProcess.java
```java
public class MainProcess {
public static void main(String[] args) {
Student student = Login.login();
if (student != null) {
System.out.println("欢迎您," + student.getName() + "!");
while (true) {
System.out.println("请选择要进行的操作:");
System.out.println("1. 选课");
System.out.println("2. 查看已选课程");
System.out.println("3. 退出");
int choice = Integer.parseInt(System.console().readLine());
if (choice == 1) {
SelectCourse.selectCourse(student);
} else if (choice == 2) {
System.out.println("您已经选了以下课程:");
for (Course course : student.getSelectedCourses()) {
System.out.println(course.getName());
}
} else if (choice == 3) {
System.out.println("成功退出系统!");
break;
} else {
System.out.println("无效的选择!");
}
}
}
}
}
```
以上是一个简单的选课系统的Java代码示例,其中实现了学生登录、选课、查看已选课程等功能。注意,这只是一个示例代码,实际应用中可能需要更多的功能和优化。
阅读全文