学生选课,只可以选择开放的课
学生类:学号 姓名 选择多门课程,只能选择开放的课
课程类: 课程号 课程名称 是否开放
管理员类:设置课程是否开放
测试类: 一个学生可以选多门课
public class Course {
/*学生选课,只可以选择开放的课
学生类:学号 姓名 选择多门课程,只能选择开放的课
课程类: 课程号 课程名称 是否开放
管理员类:设置课程是否开放
测试类: 一个学生可以选多门课
*/
private int cid;
private String cname;
private boolean judge;
public Course(int cid, String cname) {
this.cid = cid;
this.cname = cname;
}
public String getCname() {
return cname;
}
public Course() {
}
public int getCid() {
return cid;
}
public void setJudge(boolean judge) {
this.judge = judge;
}
public boolean getJudge(){
return this.judge;
}
@Override
public String toString() {
return "cid=" + cid +
", cname='" + cname + '\'';
}
}
public class Manager {
public void setcourse(Course course,boolean judge) {
course.setJudge(judge);
}
}
public class Student {
private String ID;
private String name;
ArrayList<Course> course=new ArrayList<>();
public Student(String ID, String name) {
this.ID = ID;
this.name = name;
}
public void select(Course... courses){
for (Course course:courses) {
if (course.getJudge()==true){
this.course.add(course);
}else System.out.println(course.getCid()+"\t"+course.getCname()+"课程不可选");;
}
}
@Override
public String toString() {
return "Student{" +
"ID='" + ID + '\'' +
", name='" + name + '\'' +
", course=" + course +
'}';
}
}
public class Demo {
public static void main(String[] args) {
Course course=new Course(1,"java");
Course course1=new Course(2,"c++");
Course course2=new Course(3,"python");
Manager manager=new Manager();
manager.setcourse(course,true);
manager.setcourse(course1,false);
manager.setcourse(course2,true);
Student student = new Student("123098","Tom");
student.select(course,course1,course2);
System.out.println(student.toString());
}
}