Java 计算类的x个对象的平均坡度
有谁能给我一个关于如何计算一个班级学生所有物品的平均分数的线索吗 我班的学生包括:Java 计算类的x个对象的平均坡度,java,class,object,Java,Class,Object,有谁能给我一个关于如何计算一个班级学生所有物品的平均分数的线索吗 我班的学生包括: String name // of student String [] courses // the array that contains all the courses for each student Int [] grades // the array that contains the grades for each student 我创建了一个计算单个对象(学生)平均值的方法: public dou
String name // of student
String [] courses // the array that contains all the courses for each student
Int [] grades // the array that contains the grades for each student
我创建了一个计算单个对象(学生)平均值的方法:
public double average grade stud(){
双倍合计=0;
对于(int i=0;i
但是我怎样才能创建一个计算所有学生(对象)平均成绩的方法呢已创建的?我假设学生在一个集合中。您需要迭代该集合,并将计算学生平均成绩的函数映射到每个学生。同时将这些值相加,并在迭代完成后,将其除以学生人数:
List<Student> students;
double total = 0;
for(Student s : students){
total += s.averageGradeStud();
}
double averageForAll = total / students.size();
列出学生名单;
双倍合计=0;
(学生:学生){
总计+=s.平均等级螺柱();
}
double Average Forall=总数/学生人数();
我想说,最简洁的方法是为你的学生制作一个数组列表,然后制作一个计算他们总平均成绩的方法。之后,你可以使用for循环来计算所有学生的总平均成绩
//Example
int totalGrad = 0;
for(int i = 0; i < studentList.size(); i++)
{
totalGrad += studentList.get(i).getAverageGrade();
// if you want to then average the totalGrad you can do the following
totalGrad = (totalGrad / studentList.size());
}
//示例
int totalGrad=0;
对于(int i=0;i
计算学生[平均成绩]的平均值。
//Example
int totalGrad = 0;
for(int i = 0; i < studentList.size(); i++)
{
totalGrad += studentList.get(i).getAverageGrade();
// if you want to then average the totalGrad you can do the following
totalGrad = (totalGrad / studentList.size());
}