* All Smarts university offers various undergraduate courses. Every student in the university has a unique registration number.
* To be eligible for graduation, a student
* 1. has to register for at least five subjects to be eligible for graduation.
* 2. has to score 50 or more for each subject
* * A student can register for a maximum of 8 courses.
* The university issues a grade report to every student when they graduate.
* Identify the objects involved in the scenario. Write a program to generate the grade report for students.
*/
/*所有斯马茨大学提供各种本科课程。大学生中的每一个都有一个唯一的注册号码。
* 要毕业的学生有资格
* 1。要至少5科注册成为毕业资格。
* 2。有50个或更多的得分为每个主题
*
* 学生可报名参加8课程最多。
* 该大学一年级的问题报告,每个学生毕业时。确定对象参与的情况。写一个程序来生成对学生的成绩单。
*/
/*
* University(ArrayList /ArrayList )
* Student (sName/register no/ Map )
* Course (id/cName/score/)
* 两点是在对象中进行一对多和多对多的关联,组合和聚合的关系
*/
/* * University u=new University();
* Student s1=new Student(1,"king");
* Student s2=new Student(2,"wolf");
* u.addCourse(1,"java",2.0f);
* u.addCourse(2,"C++",2.0f);
* u.addStudent(s1);
* u.addStudent(s2);
* s1.addCourseToStudent(1,1.5f);
* s2.addCourseToStudent(2,1.5f);
* s2.addCourseToStudent(1,2.0f);
*
* u.countStudentCouserNo(1)
* u.countStudentScore(1)
*/ import java.util.*;
class University{
private ArrayList studentList =new ArrayList ();
private ArrayList courseList=new ArrayList ();
//default Constructor
//behaviour
//addStudent
public void addStudent(Student astudent){
studentList.add(astudent);//aggregation聚合
}
//addCourse
public void addCourse(int id,String cName,float score){
courseList.add(new Course(id,cName,score));//composition组合
}
//countStudentCouserNo
public int countStudentCouserNo(int studentId){
int sum = 0;
// String name=null;
for(Student thisStudent:studentList){
if(thisStudent.getRegisterNo()==studentId){
// name=thisStudent.getSName();
sum+=thisStudent.getStuScoreMap().size();
}
}
// if(sum<5)System.out.println("name= "+name+",less then 5 course!");
// if(sum>8)System.out.println("name= "+name+",more then 8 course!");
return sum;
}
//countStudentScore
public float countStudentScore(int studentId){
float sum=-1.0f;
for(Student thisStudent:studentList){
if(thisStudent.getRegisterNo()==studentId){
sum = thisStudent.countTotalScore();
}
}
return sum;
}
}
class Student{
private int registerNo;
private String sName;
//private ArrayList stuScoreList=new ArrayList ();//List
private Map stuScoreMap=new HashMap ();//hashMap
//Constructor
Student(int registerNo,String sName){
this.registerNo=registerNo;
this.sName=sName;
}
//behaviour
//add course to student
public void addCourseToStudent(int courseId,float score){
stuScoreMap.put((Integer)courseId,(Float)score);
//System.out.println(stuScoreMap.size());
}
//countTotalScore
public float countTotalScore(){
float sum=0.0f;
for (Map.Entry entry : stuScoreMap.entrySet()) {
sum = sum + (Float)entry.getValue();
}
// if(sum<50)System.out.println(sName+" you less then 50 score!");
return sum;
}
//getter
public int getRegisterNo(){
return registerNo;
}
public Map getStuScoreMap(){
return stuScoreMap;
}
public String getSName(){
return sName;
}
//setter
}
class Course{
private int id;
private String cName;
private float score;
//Constructor
Course(int id,String cName,float score){
this.id=id;
this.cName=cName;
this.score=score;
}
//behaviour
//getter
//setter
}