本文为大家分享了java实现学生选课系统的具体代码,供大家参考,具体内容如下
案例要求:
学生(学号,姓名,专业,所选课程{<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.coursen