南阳教育论坛网站建设,解析域名网站,一个空间放2个网站,怎么网站建设到百度本文为大家分享了java实现学生选课系统的具体代码#xff0c;供大家参考#xff0c;具体内容如下案例要求#xff1a;学生(学号#xff0c;姓名#xff0c;专业#xff0c;所选课程{3})老师(工号#xff0c;姓名#xff0c;所教课程{3})课程(课程号#xff0c…本文为大家分享了java实现学生选课系统的具体代码供大家参考具体内容如下案例要求学生(学号姓名专业所选课程{3})老师(工号姓名所教课程{3})课程(课程号课程名学分教师已选课学生{30})选课系统代码如下//teacherpublic 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.idid;this.teachernameteachername;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.courseidcourseid;this.coursenamecoursename;this.creditcredit;this.setteacher(teacher);students new student[30];}public course(int courseid,string coursename,float credit) {super();this.courseidcourseid;this.coursenamecoursename;this.creditcredit;students new student[30];}public course(int courseid,string coursename) {super();this.courseidcourseid;this.coursenamecoursename;students new student[30];}public course() {//默认形式要有以防万一super();students new student[30];}//修改或获取属性值idnamecreditpublic void setid(int id){this.courseidid;}public int getid(){return this.courseid;}public void setname(string name){this.coursenamename;}public string getname(){return this.coursename;}public void setcredit(float credit ){this.creditcredit;}public float getcredit(){return this.credit;}public teacher getteacher() {return teacher;}public void setteacher(teacher teacher) {this.teacher teacher;}//课加入学生public boolean addstudent(student stu){boolean flag false;//标志值是否加入成功//如果学生没有选过这门课同时课的学生还没满则执行if(!isselectedstudent(stu)isnullstudent(stu)){for(int i0;iif(students[i]null){students[i]stu;flagtrue;break;}}}return flag;}//课移除学生public boolean removestudent(student stu){boolean flagfalse;if(isselectedstudent(stu)){//选过这门课for(int i0;iif(students[i]stu){students[i]null;flagtrue;break;}}}return flag;}//显示选择课程的学生public void displaystudent(){system.out.println(选择的课程this.coursename的学生有:);for(student s:students){if(s!null){system.out.print(s.getstuname() );}}system.out.println();}//子方法1学生是否选过这门课public boolean isselectedstudent(student stu){boolean flagfalse;for(student s:students){//只能用于检查不能修改if(sstu){flagtrue;break;}}return flag;}//子方法2学科学生未达到限定人数吗public boolean isnullstudent(student stu){boolean flagfalse;for(student s:students){if(snull){//还有空位flagtrue;break;}}return flag;}public static void main(string[] args) {// todo auto-generated method stub}}/*** 学生代码* author floris0811*/public class student {private string stuname;private int stuid;private string major;private course[] courses;//构造函数public student() {//不要忘super();courses new course[3];}public student(int stuid,string stuname) {super();this.stuidstuid;this.stunamestuname;courses new course[3];}public student(int stuid,string stuname,string major) {super();this.stuidstuid;this.stunamestuname;this.major major;courses new course[3];}//修改获取属性name,id,majorpublic string getstuname() {return stuname;}public void setstuname(string stuname) {this.stuname stuname;}public int getstuid() {return stuid;}public void setstuid(int stuid) {this.stuid stuid;}public string getmajor() {return major;}public void setmajor(string major) {this.major major;}//学生选课public boolean addcourse(course course){boolean flagfalse;if(!isselectedcourse(course)isnullcourse(course)){for(int i0;iif(courses[i]null){courses[i]course;course.addstudent(this);//课程也要添加学生flagtrue;break;}}}return flag;}//学生移除课程public boolean removecourse(course course){boolean flagfalse;if(isselectedcourse(course)){for(int i0;iif(courses[i]course){courses[i]null;course.removestudent(this);//在课程中移除学生flagtrue;break;}}}return flag;}//显示学生所选的课程public void displaycourse(){system.out.println(学生this.stuname所选课程有);for(course c:courses){if(c!null){system.out.print(c.getname() );}}system.out.println();}//子方法1课是否被选过public boolean isselectedcourse(course course){boolean flagfalse;for(course c:courses){if(ccourse){flagtrue;break;}}return flag;}//子方法2学生是否还有选修课位置public boolean isnullcourse(course course){boolean flagfalse;for(course c:courses){if(cnull){flagtrue;break;}}return flag;}}package test;public class choosecoursebystu {/*** 选课管理系统*/public static void main(string[] args) {student stu0 new student(1001,lily);student stu1 new student(1002,eilly);student stu2 new student(1003,floris);student stu3 new student(1004,haha);course cour0 new course(001,高数);course cour1 new course(002,线代);course cour2 new course(003,概率论);stu0.addcourse(cour0);stu0.addcourse(cour2);stu0.addcourse(cour1);stu1.addcourse(cour2);stu1.addcourse(cour0);stu2.addcourse(cour1);stu3.addcourse(cour0);stu3.addcourse(cour1);stu1.removecourse(cour2);stu0.displaycourse();cour0.removestudent(stu1);cour1.displaystudent();}}关于管理系统的更多内容请点击《管理系统专题》进行学习以上就是本文的全部内容希望对大家的学习有所帮助也希望大家多多支持萬仟网。希望与广大网友互动点此进行留言吧