学生选课统计练习java
来源:互联网 发布:交易圣经知乎 编辑:程序博客网 时间:2024/05/01 18:22
package com.java;import java.util.HashMap;import java.util.HashSet;public class Test{public static void main(String[] args){Course english=new Course("英语");Course math=new Course("数学");Student lily=new Student("Lily");Student anan=new Student("Anan");lily.addCourse(english);lily.addCourse(math);anan.addCourse(english);//s2.removeCourse("英语");SchoolClass schoolClass=new SchoolClass();schoolClass.addStudent(lily);schoolClass.addStudent(anan);//schoolClass.removeStudent("Anan");HashMap<String, Integer> mapAccount = schoolClass.mapAccount();for(HashMap.Entry<String,Integer> e : mapAccount.entrySet()){System.out.println(e.getKey()+" : "+e.getValue());}}}class Course{private String name;public Course(String name){this.name=name;}public Course(){}public String getName(){return name;}public void setName(String name){this.name = name;}}class Student{private String name;private HashSet<Course> courseSet;public Student(){super();this.courseSet=new HashSet<Course>();}public Student(String name){super();this.name = name;this.courseSet=new HashSet<Course>();}public String getName(){return name;}public void setName(String name){this.name = name;}public HashSet<Course> getCourseSet(){return courseSet;}public void setCourseSet(HashSet<Course> courseSet){this.courseSet = courseSet;}public void addCourse(Course c){this.courseSet.add(c);}public void removeCourse(String name){for(Course c:this.courseSet){if(c.getName().equals(name))this.courseSet.remove(c);}}}class SchoolClass{private HashSet<Student> studentSet;public SchoolClass(){super();studentSet=new HashSet<Student>();}public HashSet<Student> getStudentSet(){return studentSet;}public void setStudentSet(HashSet<Student> studentSet){this.studentSet = studentSet;}public void addStudent(Student s){studentSet.add(s);}public void removeStudent(String name){for(Student s:this.studentSet){if(s.getName().equals(name))this.studentSet.remove(s);}}public HashMap<String, Integer> mapAccount(){HashMap<String, Integer> resultMap=new HashMap<String,Integer>();for(Student s:this.studentSet){HashSet<Course> courseSet = s.getCourseSet();for(Course c:courseSet){Integer value = resultMap.get(c.getName());resultMap.put(c.getName(), value==null?1:++value);}}return resultMap;}}
阅读全文
0 0
- 学生选课统计练习java
- 学生选课系统java实现
- Java-List测试-学生选课
- Java-Set测试-学生选课
- Java-Map测试-学生选课
- Java模拟学生选课系统
- JAVA模拟学生选课系统
- Java-List泛型测试-学生选课
- 利用JAVA+MySQL实现学生选课系统
- MySQL实现学生选课系统的成绩统计
- java毕业设计---java swing开发学生选课系统
- JAVA-练习循环录入Java课的学生成绩,统计分数大于等于80分的学生比例
- 【编程小练习】学生成绩简单统计
- 结构体练习统计学生成绩
- 大学JAVA实验六 学生选课管理系统
- 学生选课系统-管理员功能模块设计(Java+NetBeans+SQLServer2008)
- 学生选课系统-教师功能模块设计(Java+NetBeans+SQLServer2008)
- java swing实现的学生教师选课管理系统代码
- jquery的ajax获取php文件
- 遇到xml文件不编译,需要在pom.xml文件中配置
- AsyncTask
- table与div互相嵌套注意
- How Many Tables
- 学生选课统计练习java
- UI自动化体系建设的创新实践
- 404,500等HTTP状态码表示的含义
- Oracle学前班
- Linux功耗管理(7)_Wakeup events framework
- HDU6128Inverse of sum
- Oracle数据库exp与expdp方式导入导出时改变数据库表空间及用户信息
- caffe自定义神经层
- codeforces 24C 找规律