我正在构建一个从文本文件中计算学生成绩的课程。使用的方法和字段必须完全按照它们的名称命名,因为这是一个学校项目,如果没有完全按照自己的意愿书写,我的老师会取消分数。无论如何,根据她的标准,她希望我创建一个计算数组平均值的方法,然后用另一种方法检索平均值(个人似乎有点多余,但就像我说的那样,这就是她想要的)。我构建了这个方法,并在我的getAverage(int studentNum)
方法中引用它,但是当我编译它时,它给了我一个“.class missing”的错误。我不确定为什么说实话。 eclipse提供的解决方案并不是我想要做的,因为他们建议我改变方法的参数,或创建一个全新的方法,这两者都不是我老师想要的。以下是我正在使用的内容:
public class GradeBook
{
private final int NUM_STUDENT = 5;
private final int NUM_TESTS = 4;
private String[] names = new String[5];
private char[] grades = new char[5];
private double[] scores1 = new double[4];
private double[] scores2 = new double[4];
private double[] scores3 = new double[4];
private double[] scores4 = new double[4];
private double[] scores5 = new double[4];
public void setName(int studentNum, String name)
{
names[studentNum - 1] = name;
}
public void setScores(int studentNum, double[] scores)
{
if (studentNum == 1)
{
copyArray(scores1, scores);
}
else if (studentNum == 2)
{
copyArray(scores2, scores);
}
else if (studentNum == 3)
{
copyArray(scores3, scores);
}
else if (studentNum == 4)
{
copyArray(scores4, scores);
}
else
{
copyArray(scores5, scores);
}
}
public String getName(int studentNum)
{
return names[studentNum - 1];
}
public double getAverage(int studentNum)
{
double average;
if (studentNum == 1)
{
average = calcAverage(scores1[]);
return average;
}
else if (studentNum == 2)
{
return calcAverage(scores2[]);
}
else if (studentNum == 3)
{
return calcAverage(scores3[]);
}
else if (studentNum == 4)
{
return calcAverage(scores4[]);
}
else
{
return calcAverage(scores5[]);
}
}
public char getLetterGrade(int studentNum)
{
return grades[studentNum - 1];
}
public void copyArray(double[] to, double[] from)
{
for (int i = 0 ; i < from.length ; i++)
{
from[i] = to[i];
}
}
public double calcAverage(double[] scores)
{
double sum = 0;
double average;
for (int i = 0 ; i < scores.length ; i++)
{
sum = sum + scores[i];
}
average = sum / scores.length;
return average;
}
public void assignGrade(int studentNum)
{
grades[studentNum - 1] = determineGrade(getAverage(studentNum));
}
public char determineGrade(double average)
{
if (average <= 100 && average >= 90)
{
return 'A';
}
else if (average <= 89 && average >= 80)
{
return 'B';
}
else if (average <= 79 && average >= 70)
{
return 'C';
}
else if (average <= 69 && average >= 60)
{
return 'D';
}
else
{
return 'F';
}
}
}
我确信这是一件非常容易让我失踪的事情,我只是看不到它。你们觉得怎么样?
答案 0 :(得分:3)
在方法参数中删除[]:
average = calcAverage(scores1[]);
应该是
average = calcAverage(scores1);