案例要求忘记了(大概是……):
学生(学号,姓名,专业,所选课程{<3})
老师(工号,姓名,所教课程{<3})
课程(课程号,课程名,学分,教师,已选课学生{<30})
选课系统代码如下:
//teacher
public class Teacher {
private int id;
private String teacherName;
private Course[] courses;
//构造函数
public Teacher() {
super();
courses= new Course[3];
}
public Teacher(int id,String teacherName){
this.id=id;
this.teacherName=teacherName;
courses = new Course[3];
}
//修改或是添加属性
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTeacherName() {
return teacherName;
}
public void setTeacherName(String teacherName) {
this.teacherName = teacherName;
}
}
/**
* 课程
*/
public class Course {
private String courseName;
private int courseId;
private Teacher teacher;
private float credit;
private Student[] students;
//构造函数
public Course(int courseId,String courseName,float credit,Teacher teacher) {
super();
this.courseId=courseId;
this.courseName=courseName;
this.credit=credit;
this.setTeacher(teacher);
students = new Student[30];
}
public Course(int courseId,String courseName,float credit) {
super();
this.courseId=courseId;
this.courseName=courseName;
this.credit=credit;
students = new Student[30];
}

本文通过一个实例展示了如何使用Java编程实现一个基础的学生选课系统。系统包含学生、老师和课程三个主要实体,每个实体都有相应的属性。学生可以选修不超过三门课程,老师教授不超过三门课程,每门课程限制最多30名学生选课。
最低0.47元/天 解锁文章
4208

被折叠的 条评论
为什么被折叠?



