所以我有一个作业,它要求我计算每个学生每个作业的平均分,然后计算每个作业的平均值。我能够计算每个学生的平均值,但我对每个作业的平均值以及平均值都有问题。然后我还需要计算标准偏差,我们已经得到了一个方程,但我不知道如何实现它。
最终输出应如下所示:
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.4441
我有 3 个类,2 个只是定义学生姓名和粉丝的数组,另一个是学生分数的数组。它们与问题并不真正相关。
我基本上在我的主课上运行所有东西,因为这是我可以让它正确格式化的唯一方法,而且我的时间不多了。
public class TopicManagement
{
public static void main(String[] args) throws IOException
{
System.out.println("Hello, Welcome to the Student Assesment Calculator");
//added an extra tab before the FAN to adjust for longer names
System.out.println("Student Name \t\tFAN \t\tScore 1\tScore 2\tScore 3\tScore 4\tMark\tGrade");
DecimalFormat df2 = new DecimalFormat("#.##"); //rouding to 2 decimal places
DecimalFormat df3 = new DecimalFormat("#.###"); //rounding to 3 decimal places
String [][] marks = StudentMarks.StudentMarks(); //marks Arrays is the students assignment results
String [][] nameFan = Student.Student(); //nameFan is the array containing student names and FANs
for (int 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]);
double average = score1*0.1 + score2*0.4 + score3*0.2 + score4*0.3;
String grade = null;
if (85<=average && average<101) //if average is between 85 and 100
{
grade = "HD"; //High Distinction
}
else if (75<=average && average<85) //if average if between 75 and 84
{
grade = "DN"; //Distinction
}
else if (65<=average && average<75) //if average is between 65 and 74
{
grade = "CR"; //Credit
}
else if (50<=average && average<65) //if average is between 50 and 64
{
grade = "P"; //Pass
}
else if (45<=average && average<50) //if average is between 45 and 49
{
grade = "FA"; //Fail Academic
}
else if (0<=average && average<45) //if average is between 0 and 44
{
grade = "F"; //Fail
}
System.out.println(nameFan[row][0] + "\t\t" + nameFan[row][1] + "\t" + marks[row][2] + "\t" + marks[row][3] + "\t" +
marks[row][4] + "\t" + marks[row][5] + "\t" + df2.format(average) + "%\t" + grade);
}
for (int col = 0; col < marks.length; col++)
{
ArrayList average1 = new ArrayList(10);
ArrayList average2 = new ArrayList(10);
ArrayList average3 = new ArrayList(10);
ArrayList average4 = new ArrayList(10);
double part1 = Double.parseDouble(marks[col][2]);
double part2 = Double.parseDouble(marks[col][3]);
double part3 = Double.parseDouble(marks[col][4]);
double part4 = Double.parseDouble(marks[col][5]);
average1.add(part1);
average2.add(part2);
average3.add(part3);
average4.add(part4);
double average = avera;
String grade = null;
if (85<=average && average<101) //if average is between 85 and 100
{
grade = "HD"; //High Distinction
}
else if (75<=average && average<85) //if average if between 75 and 84
{
grade = "DN"; //Distinction
}
else if (65<=average && average<75) //if average is between 65 and 74
{
grade = "CR"; //Credit
}
else if (50<=average && average<65) //if average is between 50 and 64
{
grade = "P"; //Pass
}
else if (45<=average && average<50) //if average is between 45 and 49
{
grade = "FA"; //Fail Academic
}
else if (0<=average && average<45) //if average is between 0 and 44
{
grade = "F"; //Fail
}
System.out.println("\t\t\tAverage" + " \t" + average1 + "\t" + average2 + "\t" + average3 + "\t" +
average4 + "\t" + df2.format(average) + "%\t" + grade);
}
}//end of method
}//end of class
这输出:
Hello, Welcome to the Student Assesment Calculator
Student Name FAN Score 1 Score 2 Score 3 Score 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.56% 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
我们得到的标准偏差是(希望你能解释):
SD = sqrt(sum of(each value in the data set - mean of all data in the data set)^2)
divided by number of values in the data set
我不确定如何获得最后两行,平均值和标准差。我认为我目前所拥有的是将每个分配扫描到一个 ArrayList 中,所以我的问题是,我如何获取该数组列表中的数据然后能够计算平均值或者你将如何计算平均值?我愿意接受任何建议,如果您能通过代码举个例子,我将不胜感激。
谢谢。
**EDIT**
好的,所以我已经弄清楚了如何计算平均值。我为每个分配使用了一个方法,然后我在 main 方法中调用它,这是 4 个方法中的第一个:
public static double CalculateAverage1() throws IOException
{
String [][] marks = StudentMarks.StudentMarks();
double sum = 0;
int col = 0;
for(col = 0; col < marks.length; col++)
{
double part1 = Double.parseDouble(marks[col][2]);
sum += part1;
}
return sum/col;
}
我仍然遇到标准偏差问题。
我什至无法用我的计算器计算出来。请帮忙,或者至少让我朝着正确的方向前进。
谢谢!