我正在尝试从一个文件中获取所有名称,然后从另一个文件中获取所有参与者,然后计算平均出勤率。我知道计算中的att
位是完全错误的,但我无法解决。
{
ArrayList<Match> ourList = new ArrayList(teams);
ArrayList<Match> teamsAttendance = new ArrayList<Match>();
for (Match att : ourList)
{
if (att != null && att.getTeamName().equals(team.getName()))
{
teamsAttendance.add(att);
}
}
double attendance = 0; //start attendance as 0
for (int i = 0; i < att.length; i++)
{
attendance += att[i];
}
return attendance / att.length;
}
答案 0 :(得分:0)
我猜测Match类将有一个团队名称和出勤率(数组列表)。就像获得团队名称一样,应该有一个获得考勤阵列列表。假设你可以尝试以下方法:
{
ArrayList<Match> ourList = new ArrayList(teams);
ArrayList<Match> teamsAttendance = new ArrayList<Match>();
//to store the attendance mean for each team
ArrayList<double> teamAttendanceMean = new ArrayList<double>();
//to store the attendance values of team
ArrayList<double> tempAttendance= new ArrayList<double>();
//declare outside
double attendance = 0;
for (Match att : ourList)
{
if (att != null && att.getTeamName().equals(team.getName()))
{
teamsAttendance.add(att);
}
attendance = 0;// assign 0
tempAttendance = att.getTeamAttendance();
for (int i = 0; i < tempAttendance.size(); i++)
{
attendance += tempAttendance [i];
}
//storing the mean value
teamAttendanceMean.add(attendance/tempAttendance.size());
}
}
如果我的任何假设是错误的,请告诉我,如果是的话,还要在Match类上发布信息。