You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1020 B
49 lines
1020 B
package basic;
|
|
|
|
/**
|
|
* 学科类,实现学科与课程的一对多关联关系
|
|
*/
|
|
public class Subject {
|
|
private int id;
|
|
private String name;
|
|
|
|
// 该学科下的所有课程(一对多关系)
|
|
private java.util.List<Course> courses;
|
|
|
|
public Subject(int id, String name) {
|
|
this.id = id;
|
|
this.name = name;
|
|
this.courses = new java.util.ArrayList<>();
|
|
}
|
|
|
|
// 添加课程
|
|
public void addCourse(Course course) {
|
|
courses.add(course);
|
|
}
|
|
|
|
// 移除课程
|
|
public void removeCourse(Course course) {
|
|
courses.remove(course);
|
|
}
|
|
|
|
// Getters and Setters
|
|
public int getId() {
|
|
return id;
|
|
}
|
|
|
|
public void setId(int id) {
|
|
this.id = id;
|
|
}
|
|
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
|
|
public void setName(String name) {
|
|
this.name = name;
|
|
}
|
|
|
|
public java.util.List<Course> getCourses() {
|
|
return new java.util.ArrayList<>(courses);
|
|
}
|
|
} |