【发布时间】:2011-05-21 12:52:18
【问题描述】:
我已经在这里潜伏了一段时间,但是我遇到了一个问题,我在为作业编写的一些 Java 程序中无法解决。我敢打赌,它们并不太难弄清楚,但我就是不明白。
我遇到了类似这样的错误:
RugbyTeamLadderEditor.java:125: cannot find symbol
symbol : method findAveragePoints(java.util.ArrayList<RugbyTeam>)
location: class RugbyTeamLadderEditor
double averagePointsToBePrinted = findAveragePoints(rugbyTeams);
我有三个类,从具有主要方法的类(RugbyTeamLadderEditor)中,我可以调用构造函数类,但不能调用其中包含一些方法的其他类(第 1 部分)。我应该对包裹做些什么吗? - 我只知道在我正在做的这个介绍性编程课程中我没有学到任何关于包的知识,而且我不确定如果我使用它们会如何收到它们。
我的代码有几百行,所以我把它们放在了 pastebin 中——我希望我这样做没有违反任何错误:/ 每个类都在它自己的 .java 文件中。
干杯!
编辑:我的代码的一些片段:
在 RugbyTeamLadderEditor.java 中:
// if the identification number is equal to 5, then print out the average points of all of the teams in the ArrayList
else if (identificationNumber == 5)
{
double averagePointsToBePrinted = findAveragePoints(rugbyTeams);
}
在 Part1.java 中:
/**
* This method takes a RugbyTeam ArrayList and returns a
* double that represents the average of the points of all
* of the rugby teams
*/
public static double findAveragePoints(ArrayList<RugbyTeam> rugbyTeams)
{
// If there are no objects in the ArrayList rugbyTeams, return 0
if (rugbyTeams.size() == 0)
return 0;
// Declare a variable that represents the addition of the points of each team;
// initialise it to 0
double totalPoints = 0;
// This is a code-cliche for traversing an ArrayList
for (int i = 0; i < rugbyTeams.size(); i++)
{
// Find then number of points a team has and add that number to totalPoints
RugbyTeam r = rugbyTeams.get(i);
totalPoints = totalPoints + r.getPoints();
}
// Declare a variable that represents the average of the points of each teams,
// i.e. the addition of the points of each team divided by the number of teams
// (i.e. the number of elements in the ArrayList); initialise it to 0
double averagePoints = totalPoints / rugbyTeams.size();
return averagePoints;
}
它还没有完全完成——我仍然需要放入一个 print 语句来打印那个双精度,但现在这无关紧要,因为我实际上无法让那个双精度具有一个值。
【问题讨论】:
-
发布您的代码片段。然后人们可以提供更好的帮助。
-
谢谢,这是个好主意 - 我发布了一些相关的代码,我确信我能够推断出我应该如何处理其他受影响的代码(其中我已经删除了,只是因为它们不起作用 - 一旦我知道该怎么做,我会从头开始写)。