【发布时间】:2016-11-27 18:29:10
【问题描述】:
您好,我是 Java 新手,我正在编写一个模拟跳水比赛的简单程序。我使用 NetBeans,但我不知道为什么它会给我这个错误。 代码是这样的:
package agoneskataduseon;
import java.util.Scanner;
public class AgonesKataduseon {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int numAth, numJud, numDiv;
System.out.print("Give the number of the athletes in the competition : ");
numAth = input.nextInt();
System.out.print("Give the number of the judges : ");
numJud = input.nextInt();
System.out.print("Give the numbe rof dives : ");
numDiv = input.nextInt();
DivingCompetition game = new Diving Competition(numAth, numJud, numDiv);
}
}
DivingCompetition 类(未完成):
import java.util.Scanner;
public class DivingCompetition {
int numa;
int numj;
int numd;
Athlete[] arr1 = new Athlete[12];
Athlete[] arr2 = new Athlete[12];
public DivingCompetition(int numAthletes, int numJudges, int numDives){
numa = numAthletes;
numj = numJudges;
numd = numDives;
}
public void readAthletesName(){
String nam;
int i=0;
Scanner input = new Scanner(System.in);
while(i < numa){
System.out.print("Give the name of athlete num "+(i+1)+" : ");
nam = input.nextLine();
arr1[i] = new Athlete(nam);
i++;
}
}
public void runCompetition(){
int i=0;
Dive dv = new Dive(numj);
while(i<12){
arr1[i].addDive(dv);
}
}
}
还有运动员课:
public class Athlete {
String names;
Dive[] arrayd = new Dive[6];
double fullScore;
int point;
public Athlete(String name){
names = name;
fullScore = 0;
point = 0;
}
public void addDive(Dive dive){
arrayd[point] = dive;
fullScore = fullScore + arrayd[point].computeScore();
point++;
}
}
我也会给你上潜水课,但我不明白这样做的意义
NetBeans 在主函数中给我一个错误: 找不到标志 符号:类DivingCompetition 位置:类 AgonesKataduseon
我的问题是为什么它会给我这个错误? 如果我尝试在主函数中创建 Athlete 或 Dive 对象,也会发生此问题
【问题讨论】:
-
我认为你必须导入类。试试
Ctrl-Shift-I。来源:netbeans.org/project_downloads/usersguide/shortcuts-80.pdf -
因为
DivingCompetition不在同一个包中。 -
我尝试了 Ctrl-Shift-I 方法,但它在导入语句中没有说明要修复。你能建议我另一种解决方案吗?我是 NetBeans 新手,不习惯它的工作原理
-
我想我找到了问题所在。所以看来我已经在默认包中编写了类,而不是在正确的包中......我觉得你太愚蠢了,你无法想象我寻找解决方案多久了......