在IDEA中用JAva设计一个简单的学生选课系统,并可以完成添加、删除、修改、查询相关信息 。 这个系统包含以下类: 描述课程基本信息类(课程编号,课程名,学分 ); 描述学生基本信息类(学号,姓名,专业方向 ); 记录选课结果的类(课程,选课的学生,课程最多人数,当前人数 ); 测试类(设定或输入最多人数,创建课程对象,创建选课学生对象,创建选课对象,显示选课情况 )
时间: 2024-03-04 20:47:58 浏览: 56
基于JAVA的学生选课系统设计
好的,这是一个比较复杂的问题,我会尽力回答。首先,我们需要设计以下几个类:
1.描述课程基本信息类(课程编号,课程名,学分 );
```
public class Course {
private String courseId;
private String courseName;
private int credit;
public Course(String courseId, String courseName, int credit) {
this.courseId = courseId;
this.courseName = courseName;
this.credit = credit;
}
// Getter and Setter methods
}
```
2.描述学生基本信息类(学号,姓名,专业方向 );
```
public class Student {
private String studentId;
private String name;
private String major;
public Student(String studentId, String name, String major) {
this.studentId = studentId;
this.name = name;
this.major = major;
}
// Getter and Setter methods
}
```
3.记录选课结果的类(课程,选课的学生,课程最多人数,当前人数 );
```
public class CourseSelection {
private Course course;
private Student student;
private int maxNumOfStudents;
private int currentNumOfStudents;
public CourseSelection(Course course, Student student, int maxNumOfStudents, int currentNumOfStudents) {
this.course = course;
this.student = student;
this.maxNumOfStudents = maxNumOfStudents;
this.currentNumOfStudents = currentNumOfStudents;
}
// Getter and Setter methods
}
```
4.测试类(设定或输入最多人数,创建课程对象,创建选课学生对象,创建选课对象,显示选课情况 )
```
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入最多人数: ");
int maxNumOfStudents = scanner.nextInt();
Course math = new Course("001", "高等数学", 5);
Course chinese = new Course("002", "语文", 3);
Course english = new Course("003", "英语", 4);
List<Student> studentList = new ArrayList<>();
studentList.add(new Student("1001", "张三", "计算机科学与技术"));
studentList.add(new Student("1002", "李四", "软件工程"));
List<CourseSelection> courseSelectionList = new ArrayList<>();
courseSelectionList.add(new CourseSelection(math, studentList.get(0), maxNumOfStudents, 1));
courseSelectionList.add(new CourseSelection(chinese, studentList.get(0), maxNumOfStudents, 1));
courseSelectionList.add(new CourseSelection(english, studentList.get(1), maxNumOfStudents, 1));
for (CourseSelection courseSelection : courseSelectionList) {
System.out.println(courseSelection.getStudent().getName() + "选了" + courseSelection.getCourse().getCourseName());
}
}
}
```
以上就是一个简单的学生选课系统的设计。当然,还需要完善和优化,但这是一个基本的框架。希望能够帮到你。
阅读全文