本文为大家分享了java实现学生选课系统的具体代码,供大家参考,具体内容如下
我们提供的服务有:成都网站建设、成都网站设计、微信公众号开发、网站优化、网站认证、汕头ssl等。为超过千家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的汕头网站制作公司
案例要求:
学生(学号,姓名,专业,所选课程{<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]; } public Course(int courseId,String courseName) { super(); this.courseId=courseId; this.courseName=courseName; students = new Student[30]; } public Course() {//默认形式,要有以防万一 super(); students = new Student[30]; } //修改或获取属性值id,name,credit, public void setId(int id){ this.courseId=id; } public int getId(){ return this.courseId; } public void setName(String name){ this.courseName=name; } public String getName(){ return this.courseName; } public void setCredit(float credit ){ this.credit=credit; } 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 i=0;i
/** * 学生代码 * @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.stuId=stuId; this.stuName=stuName; courses = new Course[3]; } public Student(int stuId,String stuName,String major) { super(); this.stuId=stuId; this.stuName=stuName; this.major = major; courses = new Course[3]; } //修改获取属性name,id,major public 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 flag=false; if(!isSelectedCourse(course)&&isNullCourse(course)){ for(int i=0;i
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(); } }
关于管理系统的更多内容请点击《管理系统专题》进行学习
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持创新互联。