怎么写这个方法 为SchoolClass类写一个方法,统计每门课程的选课人数 Map account();该方法返回一个Map,key代表课程,value代表人数。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.util.*;public class SchoolClass { private HashSet<Student> allStudent; public boolean addStudent(Student s){ allStudent.add(s); return true; } public Student removeStudent(String name){ Student stu=new Student(name); allStudent.remove(stu); return stu; } public SchoolClass(){ allStudent=new HashSet<Student>(); } public Map<Course,Integer> account(){ Map<Course,Integer> map=new HashMap<Course,Integer>(); Set<Course> courseSet=new HashSet<Course>(); for(Student student:allStudent){ for(Course course:student.getAllCourse()){ courseSet.add(course); } } for(Course cou:courseSet){ int j=0; for(Student stu:allStudent){ if(stu.getAllCourse().contains(cou)){ j++; } } map.put(cou, j); } return map; }}结贴吧 1,定义一个Course类,代表课程;定义一个Student类,代表学生,在Student类中包含一个属性是一个HashSet的对象,用来存储该学生所选的所有课程,并提供相应的addCourse(Course c)方法和removeCourse(String name)方法,表示添加一门选课和删除一门选课(删除选课时通过传课程名参数来确定)。2,定义一个类SchoolClass代表班级,该类中包含一个属性是一个HashSet的对象,用来存储该班级中所有的Student,并提供相应的addStudent(Student s)方法和removeStudent(String name)方法,表示添加一名学生和删除一名学生(删除学生时通过传学生姓名参数来确定)。3,为SchoolClass类写一个方法,统计每门课程的选课人数 Map account();该方法返回一个Map,key代表课程,value代表人数。 JAVA初学者请教各位老师,java里面怎么做html 如何布局更完美???? 收集java程序员所看的杂自,请java程序员把自己所看的杂自名列出来 关于移位>>>的问题,很奇怪的问题,不知道大家发现没有? 英文操作系统对编码有影响吗? 有个问题想不通? 推荐:<Jakata Poi HSSF:纯java的Excel解决方案> 在Apache+Tomcat 4.0如何使用jdbc连接oracle String转换到int 哪里有media的包 各位路过的大侠都来看看啊~在线等答案,大作业~~~~(>_<)~~~~ doc数据 Base64 解码
public class SchoolClass {
private HashSet<Student> allStudent;
public boolean addStudent(Student s){
allStudent.add(s);
return true;
}
public Student removeStudent(String name){
Student stu=new Student(name);
allStudent.remove(stu);
return stu;
}
public SchoolClass(){
allStudent=new HashSet<Student>();
}
public Map<Course,Integer> account(){
Map<Course,Integer> map=new HashMap<Course,Integer>();
Set<Course> courseSet=new HashSet<Course>();
for(Student student:allStudent){
for(Course course:student.getAllCourse()){
courseSet.add(course);
}
}
for(Course cou:courseSet){
int j=0;
for(Student stu:allStudent){
if(stu.getAllCourse().contains(cou)){
j++;
}
}
map.put(cou, j);
}
return map;
}
}
结贴吧
2,定义一个类SchoolClass代表班级,该类中包含一个属性是一个HashSet的对象,用来存储该班级中所有的Student,并提供相应的addStudent(Student s)方法和removeStudent(String name)方法,表示添加一名学生和删除一名学生(删除学生时通过传学生姓名参数来确定)。
3,为SchoolClass类写一个方法,统计每门课程的选课人数 Map account();该方法返回一个Map,key代表课程,value代表人数。