2016-11-27 250 views
0

嗨,我是新來的Java和我正在寫一個簡單的程序,將模擬跳水比賽。我使用NetBeans,我無法找出它爲什麼會給我這個錯誤。 的代碼是這樣的:找不到符號錯誤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是givi納克我的錯誤主要功能: 找不到符號 符號:類DivingCompetition 位置:類AgonesKataduseon

我的問題是,爲什麼它給了我這個錯誤? 這個問題也會發生,如果我試圖使主體功能內的運動員或潛水的對象

+0

我認爲你必須導入這個類。嘗試'Ctrl-Shift-I'。來源:https://netbeans.org/project_downloads/usersguide/shortcuts-80.pdf – markspace

+0

因爲'DivingCompetition'不在同一個包中。 –

+0

我嘗試了Ctrl-Shift-I方法,但它沒有在導入語句中修復。你能給我提供另一種解決方案嗎?我是新來的NetBeans,我沒有用它如何工作 –

回答

0

Netbeans將嘗試幫助並給你建議,如果你問它,修復你的代碼。您只需將光標放在問題所在的行上,然後按Alt + 輸入

Fix Code

,當你將鼠標懸停在錯誤陳述它可以使你在錯誤消息的底部此鍵盤快捷鍵。

請參閱手冊中的Code Assistance頁面瞭解更多信息。