我有一个包含姓名,老师,学生的课程[];
public class Course implements Comparable<Course> {
variables ...
private Student[] students;
public Course(variables... int maxStudents) {
variables...
this.maxStudents = maxStudents;
students = new Student[maxStudents];
}
我有courseGrades课
public class GradesList{
private Course course;
private ArrayList<Integer> grades;
public ListaOcen(Course course)
{
this.course = course;
grades = new ArrayList<>();
}
我也有学生班
public class Student extends Person {
variables...
private ArrayList<ListaOcen> degresList;
public Student(variables...) {
super(variables...);
course = new Course[5];
degresList = new ArrayList<>();
}
我不知道该如何准确地将courseGrades类作为学生类的变量传递,以及以后如何填写该成绩列表。到目前为止,我已经创建了此功能
public void addDeggre(Integer deggre) {
if(deggre > 1 && deggre < 7)
grades.add(deggre);
}
答案 0 :(得分:0)
要在Course类中使用地图,请包括:
private TreeMap<Student, Integer> grades = new TreeMap<>();
private ArrayList<Student> students = new ArrayList<>();
然后,课程课程提供一种添加学生,设置成绩并获得成绩的方法:
public void addStudent( Student s ) {
students.add(s);
grades.put(s,0);
}
public void setGrade( Student s, int grade ) {
grades.replace(s,grade);
}
public int getGrade( Student s ) {
return grades.get(s).intvalue();
}
当然,如果传递的Student不在地图中,则您需要添加代码来处理错误,例如setGrade()和getGrade()。