2014-07-04 51 views
-1

我正在模擬沿水平線移動的錯誤的程序,當我在自己的類中測試它時,我的代碼正常工作,但是當我嘗試測試構造函數和測試類中的方法我收到一個錯誤,在我的構造函數Bug中發現「無法找到符號」。我還是新來的Java,所以我不知道我們的錯誤是。 編輯。構造函數和方法在測試類中不工作java

/* 
* To change this license header, choose License Headers in Project Properties. 
* To change this template file, choose Tools | Templates 
* and open the template in the editor. 
*/ 

package bugtester; 
/** 
* 
* @author Luke 
*/ 
public class BugTester { 

    /** 
    * @param args the command line arguments 
    */ 
    public static void main(String[] args) { 

     Bug juneBug = new Bug(0); 
     juneBug.move(); 
     juneBug.turn(); 
     juneBug.move(); 
     System.out.println(juneBug.getposition()); 
    } 

} 

/* 
* To change this license header, choose License Headers in Project Properties. 
* To change this template file, choose Tools | Templates 
* and open the template in the editor. 
*/ 

package bug; 

/** 
* 
* @author Luke 
*/ 
public class Bug { 

    /** 
    * @param args the command line arguments 
    */ 

    public int position; 
    public int turner = 1; 
    public static void main(String[] args) { 

     Bug juneBug = new Bug(0); 
     juneBug.move(); 
     juneBug.turn(); 
     juneBug.move(); 
     juneBug.move(); 
     System.out.println(juneBug.getposition()); 

    } 
    public Bug(int initialPosition){ 
     position = initialPosition; 
     turner = 1; 

    } 
    public void turn(){ 

     turner = turner + 1; 
    } 
    public void move(){ 
     if (turner % 2 == 0){ 
      position = position - 1; 
     }else{ 
      position = position + 1; 
    } 

    } 
    public int getposition(){ 
     return position; 
} 
} 
+0

你有沒有爲你的班級添加'import'? –

+7

你做過任何研究嗎?當你不知道你在做什麼時,「找不到符號」是一個非常常見的錯誤。 –

+0

我不這麼認爲,我會怎麼做呢? – user3806295

回答

0

你把你的類中完全獨立的包,而不是import荷蘭國際集團BugBugTester。把這兩門課放在package bug

+0

我不明白該怎麼做,我該怎麼做? – user3806295

+0

@chrylis我指出你說的,但是.....? –

+0

@ user3806295你把'BugTester'放在'bug'裏的方式與'Bug'相同。使用您的IDE或手動編輯並移動「BugTester.java」。 – chrylis