大家好,又见面了,我是你们的朋友全栈君。
展开全部
public class Student{
Integer id;//等其他String,int型
Set teachers;
Set courses;
public Student(Integer id){
this.id = id;
}
public Student(Integer id, Set teachers, Set courses){
this.id = id;
this.teachers = teachers;
this.courses = courses;
}
public Integer getId(){
return id;
}
public void setId(Integer id){
this.id = id;
}
//其他类型略
public Set getTeachers(){
return teachers;
}
public setTeachers( Set teachers){
this.teachers = teachers;
}
//课程类似
}
教师类,636f707962616964757a686964616f31333335333761课程类类似。
以下是实现:public static void main(String [] args){
Student s1 = new Student(1);
Teacher t1 = new Teacher(1);
Teacher t2 = new Teacher(2);
Course c1 = new Course(1);
Course c2 = new Course(2);
Set studentSet = new HashSet();
studentSet.add(s1);
Set teacherSet = new HashSet();
teacherSet.add(t1);
teacherSet.add(t2);
Set courseSet = new HashSet();
courseSet.add(c1);
courseSet.add(c2);
s1.setTeachers(teacherSet );
t1.setStudents(studentSet);
t2.setStudents(studentSet);
s1.setCourses(courseSet);
c1.setStudent(studentSet);
c2.setStudent(studentSet);
//老师课程同理
}
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/156458.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...