-
public Set<Course> courses; public Student(String id,String name){ this.id = id; this.name = name; this.courses = new HashSet<Course>(); }
查看全部 -
package lmr; 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(); } }
查看全部 -
package lmr; public class Student{ public String id; public String name; public Set courses; }
查看全部 -
package lmr; import java.util.List; public class ListTest{ public List coursesToSelect; public ListTest(){ this.coursesToSelect = new ArrayList(); } }
查看全部 -
List是元素有序并且可以重复的集合,被称为序列
List可以精确的控制每个元素的插入位置,或删除某个位置元素
ArrayList——数组序列,是List的一个重要实现类
查看全部 -
public static void main(String[] args){ MapTest mt = new MapTest(); mt.testPut(); mt.testKeySet(); mt.testRemove(); mt.testEntrySet(); }
查看全部 -
public static void main(String[] args){ MapTest mt = new MapTest(); mt.testPut(); mt.testKeySet(); mt.testRemove(); mt.testEntrySet(); }
查看全部 -
public void testKeySet(){ Set<String>keySet = student.keySet(); System.out.println("总共有:"+students.size()+"个学生"); for(String stuId:keySet){ Student st = students.get(stuId); if(st!=null) System.out.println("学生:"+st.name); } }
查看全部 -
public int compare(Student o1,Student o2){ return o1.name.compareTo(o2.name); }
查看全部 -
public static void main(String[] args){ MapTest mt = new MapTest(); mt.testPut(); mt.testKeySet(); mt.testModify(); mt.testEntrySet(); } public void testContainsKeyOrValue(){ System.out.println("请输入要查询的学生ID"); Scanner console = new Scanner(System.in); String id = console.next(); System.out.println("您输入的学生ID为:"+id+",在学生映射表中是否存在:"+students.containsKey(id)); if(students.containsKey(id)) System.out.println("对应的学生为:"+students.get(id).name); }
查看全部 -
public void createStudentAndSelectCours(){ Student student = newStudent("1","小明"); System.out.println("欢迎学生:"+student.name+"选课"); Scanner console = new Scanner(System.in); for(int i=0;i<3;i++){ System.out.println("请输入课程ID"); String courseId = console.next(); for(Course cr : coursesToSelct){ if(cr.id.equals(courseId)){ student.courses.add(cr); } } } } public static void main(String[] args){ SetTest st = new SetTest(); Sst.testAdd(); st.testForEach(); st.createStudentAandSelectCours(); st.testSetContains(); }
查看全部 -
public boolean equals(Obiect obj){ if(this==obj){ return true; } if(obj==null) return false; if(!(obj instanceof Course)) return false; Course course = (course)obj; if(this.name==null){ if(course.name==null) return true; else return false; }else{ if(this.name.equals(course.name)) return true; else return false; } }
查看全部 -
package lmr; public class SetTest{ public List<Course> coursesToSelect; public SetTest(){ coursesToSelect = new ArrayList<Course>(); } public static void main(String[] args){ SetTest st = new SetTest(); st.testAdd(); st.testForEach(); Studrnt student =new Student("1","小明"); Scanner console = new Scanner(System.in); for(int i =0;i<3;i++){ System.out.println("请输入课程"); String couresId0 = console.next(); for(Course cr : st.coursesToSelect){ if(cr.id.equals(courseld)) } } } }
查看全部 -
package lmr; public class TestGeneric{ public List<Course>courses; public TestGeneric(){ thid.courses = new ArrayList<Course> } public static void main(String[] args){ } }
查看全部 -
public void testType(){ coursesToSelect.add("lmr"); } public static void main(String[] args){ ListTest lt = new ListTest(); lt.testAdd(); lt.testType(); lt.testForEach(); }
查看全部
举报
0/150
提交
取消