Public course students {
private int id
Private string name;
Private distribution list & ltClass & gtclassids
public Student(int id,String name,List & ltClass & gtclass_id){
this.id = id
this.name = name
this.classids = class _ id
}
}
Public course teacher {
private int id
Private string name;
Public teacher (int id, string name) (
this.id = id
this.name = name
}
}
Public Class {
private int id
Private string name;
Private teacher _ id
public Class(int id,String name,Teacher teacher_id ){
this.id = id
this.name = name
This.teacher _ id = teacher id;
}
Common class test {
/**
* @param args
*/
Public static void main(String[] args) {
Teacher t 1 = new teacher (1 1, "Mr. Yao Yao");
Teacher t2 = new teacher (22, "sweet teacher");
Teacher t3 = new teacher (33, "stupid teacher");
C 1 class = new class (1, "Chinese", t1); //The relationship between the course and the teacher is 1: 1.
C2 class = new class (2, "Mathematics", T2);
C3 class = new class (3, "English", T3);
List & lt class & gt list1= new ArrayList < Class & gt();
list 1 . add(c 1);
list 1 . add(C2);
List & lt class & gt list2 = new ArrayList & lt class & gt ();
list 2 . add(c 1);
list 2 . add(C3);
Student s 1 = freshman (00 1, "Zhang San", list1); //Relationship between students and courses 1: m
Student s2 = freshman (002, "Li Si", List 2);
}
}
In this way, the relationship between students and teachers is m: n.