public class Course {
public String id;
public String name;
public Course(String id,String name){
this.id=id;
this.name=name;
}
}import java.util.HashSet;
import java.util.Set;
public class Student {
public String id;
public String name;
public Set courses;
public Student(String id,String name){
this.id=id;
this.name=name;
this.courses=new HashSet();
}
}import java.util.ArrayList;
import java.util.List;
public class TestAdd {
public List<Course> courseAll;
public TestAdd(){
this.courseAll=new ArrayList();
}
public void Add(){
Course cr1=new Course("1","数据结构");
courseAll.add(cr1);
Course cr2=new Course("2","C语言");
courseAll.add(1, cr2);
courseAll.add(new Course("3","数学"));
courseAll.add(new Course("4","语文"));
}
public void use(){
TestAdd it=new TestAdd();
it.Add();
for(Course cr:it.courseAll){
System.out.println("id: "+cr.id+" name: "+cr.name);
}
}
}public class Main {
public static void main(String[] args) {
TestAdd add=new TestAdd();
add.Add();
add.use();
}
}
添加回答
举报
0/150
提交
取消