我正在努力为我的作业找到标准偏差,我已经完成了其他所有事情,我只是在最后一点挣扎。简而言之,我的作业问题是:我收到了一组学生的作业结果文本文件(必须是任意数字)。唯一给出的数据是学生姓名、粉丝和他们的成绩,你需要计算他们的平均成绩和标准差。输出应如下所示:
Student Name FAN Part 1 Part 2 Part 3 Part 4 Mark Grade
Adam Adamson adam0001 85.4 79.8 82.4 86.1 82.77% DN
Bethany Bright brig0001 89.7 85.6 84.2 82.9 84.92% DN
Cameron Carlson carl0001 55.45 49.82 60.4 42.27 50.23% P
David Dawson daws0001 72.6 78.49 80.2 65.88 74.46% CR
Evelyn Ellis elli0001 50.2 35.88 48.41 58.37 46.57% FA
Frances Fitz fitz0001 78.9 75.67 82.48 79.1 78.38% DN
Greg Gregson greg0001 24.3 32.88 29.72 28.4 30.05% F
Harriett Hope hope0001 52.2 58.93 61.5 63.44 60.12% P
Ivan Indigo indi0001 88.4 91.23 90.05 92.46 91.08% HD
Jessica Jones jone0001 82.33 89.74 81.3 84.85 85.84% HD
Average 67.948 67.804 70.066 68.377 68.44% CR
StdDev 19.4442
我知道我需要使用的方程式,我知道我需要使用哪些数字我只是不知道如何获得它们。我会告诉你我需要做什么,希望你能进一步理解我的代码:
the total of the averages divided by 10 = 68.442
sum = (82.77-68.442)^2 + (84.92-68.442)^2 + (50.23-68.442)^2 + ... + (85.84-68.442)^2
StdDev = Math.sqrt(sum/10)
stdDev = 19.4442
我为此使用了 3 个课程,我的主课程主题管理,一个学生课程,其中包含一个包含学生姓名和粉丝的数组(两者都与我的问题无关,但我认为我最好只是设置场景),最后StudentsMarks 类,其中包含我的 StdDec 方法,如下所示:
public static double StdDev() throws IOException
{
String [][] marks = StudentMarks.StudentMarks();
double mean = 0, average = 0, stdDev = 0;
int row = 0;
for(row = 0; row < marks.length; row++)
{ //ROW,COL
double score1 = Double.parseDouble(marks[row][2]); //parsing the data from the array into a double
double score2 = Double.parseDouble(marks[row][3]);
double score3 = Double.parseDouble(marks[row][4]);
double score4 = Double.parseDouble(marks[row][5]);
average = score1*0.1 + score2*0.4 + score3*0.2 + score4*0.3;
mean = average/row;
stdDev = Math.sqrt(Math.pow(average - mean,2)/row);
}
return stdDev;
}