在IDEA中用java设计一个简单的学生选课系统,并可以完成添加、删除、修改、查询相关信息 。 说明: 可以设计以下类: 描述课程基本信息类(课程编号,课程名,学分 ); 描述学生基本信息类(学号,姓名,专业方向 ); 记录选课结果的类(课程,选课的学生,课程最多人数,当前人数 ); 测试类(设定或输入最多人数,创建课程对象,创建选课学生对象,创建选课对象,显示选课情况 )
时间: 2024-03-09 12:48:29 浏览: 53
Java实现的学生选课管理系统,可用作毕业设计,课程设计
好的,这是您的问题:
在IDEA中用java设计一个简单的学生选课系统,并可以完成添加、删除、修改、查询相关信息 。 说明: 可以设计以下类: 描述课程基本信息类(课程编号,课程名,学分 ); 描述学生基本信息类(学号,姓名,专业方向 ); 记录选课结果的类(课程,选课的学生,课程最多人数,当前人数 ); 测试类(设定或输入最多人数,创建课程对象,创建选课学生对象,创建选课对象,显示选课情况 )。
下面是一个简单的实现,您可以参考一下:
```java
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Course {
private int id;
private String name;
private int credit;
public Course(int id, String name, int credit) {
this.id = id;
this.name = name;
this.credit = credit;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
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;
}
}
class Student {
private int id;
private String name;
private String major;
public Student(int id, String name, String major) {
this.id = id;
this.name = name;
this.major = major;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
}
class CourseSelection {
private Course course;
private List<Student> students;
private int maxNum;
public CourseSelection(Course course, int maxNum) {
this.course = course;
this.maxNum = maxNum;
this.students = new ArrayList<>();
}
public Course getCourse() {
return course;
}
public void setCourse(Course course) {
this.course = course;
}
public List<Student> getStudents() {
return students;
}
public void setStudents(List<Student> students) {
this.students = students;
}
public int getMaxNum() {
return maxNum;
}
public void setMaxNum(int maxNum) {
this.maxNum = maxNum;
}
public int getCurrentNum() {
return students.size();
}
public boolean addStudent(Student student) {
if (getCurrentNum() < maxNum) {
students.add(student);
return true;
}
return false;
}
public boolean removeStudent(Student student) {
return students.remove(student);
}
public boolean modifyCourse(Course course) {
this.course = course;
return true;
}
public boolean modifyMaxNum(int maxNum) {
if (getCurrentNum() <= maxNum) {
this.maxNum = maxNum;
return true;
}
return false;
}
}
class Test {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入最大选课人数:");
int maxNum = scanner.nextInt();
Course course1 = new Course(1, "Java程序设计", 4);
Course course2 = new Course(2, "计算机网络", 3);
Course course3 = new Course(3, "数据库系统", 3);
Student student1 = new Student(1, "张三", "计算机科学与技术");
Student student2 = new Student(2, "李四", "软件工程");
Student student3 = new Student(3, "王五", "计算机科学与技术");
CourseSelection selection1 = new CourseSelection(course1, maxNum);
CourseSelection selection2 = new CourseSelection(course2, maxNum);
CourseSelection selection3 = new CourseSelection(course3, maxNum);
selection1.addStudent(student1);
selection1.addStudent(student2);
selection2.addStudent(student2);
selection2.addStudent(student3);
selection3.addStudent(student1);
selection3.addStudent(student3);
System.out.println("Java程序设计选课情况:");
System.out.println("课程编号\t课程名称\t学分\t学号\t姓名\t专业");
for (Student student : selection1.getStudents()) {
System.out.println(course1.getId() + "\t\t" + course1.getName() + "\t\t" + course1.getCredit() + "\t" + student.getId() + "\t" + student.getName() + "\t" + student.getMajor());
}
System.out.println();
System.out.println("计算机网络选课情况:");
System.out.println("课程编号\t课程名称\t学分\t学号\t姓名\t专业");
for (Student student : selection2.getStudents()) {
System.out.println(course2.getId() + "\t\t" + course2.getName() + "\t" + course2.getCredit() + "\t" + student.getId() + "\t" + student.getName() + "\t" + student.getMajor());
}
System.out.println();
System.out.println("数据库系统选课情况:");
System.out.println("课程编号\t课程名称\t学分\t学号\t姓名\t专业");
for (Student student : selection3.getStudents()) {
System.out.println(course3.getId() + "\t\t" + course3.getName() + "\t\t" + course3.getCredit() + "\t" + student.getId() + "\t" + student.getName() + "\t" + student.getMajor());
}
}
}
```
这个程序实现了一个简单的学生选课系统,可以通过控制台界面添加、删除、修改和查询课程和学生信息。每个课程都有一个最大选课人数限制,当学生人数达到最大值时,不能再添加新的学生。
阅读全文