2015-12-29 220 views
-2

有了這段代碼,我得到一個錯誤:Package Hangman缺失。所以我不能使用任何Hangman導入。我在哪裏可以找到這個?圖書館netbeans Java

import java.util.Scanner; 
import hangman.Hangman; // I have imported it here 

public class Hangman { 
    public static void main(String[] args) { 
     Scanner reader = new Scanner(System.in); 
     Hangman hangman = new Hangman(); 

     System.out.println("************"); 
     System.out.println("* Hangman *"); 
     System.out.println("************"); 
     System.out.println(""); 
     printMenu(); 
     System.out.println(""); 

     while (hangman.gameOn()) { 
      System.out.println(" Type a command: "); 
      String command = reader.nextLine(); 
      if (command.equals("quit")) { 
       break; 
      } 

      System.out.println("Thank you for playing!"); 
     } 
    } 

    public static void printMenu() { 
     System.out.println(" * menu *"); 
     System.out.println("quit - quits the game"); 
     System.out.println("status - prints the game status"); 
     System.out.println("a single letter uses the letter as a guess"); 
     System.out.println("an empty line prints this menu");  
    } 
} 
+0

你的進口在哪裏?你的項目結構是什麼? – SMA

回答

0

您很可能試圖導入類本身,即Hangman

你的代碼更改爲以下,看看它的工作原理:

package hangman; //Notice the change here. We are now declaring the package, not importing it. 

import java.util.Scanner; 

public class Hangman { 

    public static void main(String[] args) { 


     Scanner reader = new Scanner(System.in); 
     Hangman hangman = new Hangman(); 

     System.out.println("************"); 
     System.out.println("* Hangman *"); 
     System.out.println("************"); 
     System.out.println(""); 
     printMenu(); 
     System.out.println(""); 

     while (hangman.gameOn()) { 
      System.out.println(" Type a command: "); 
      String command = reader.nextLine(); 
      if (command.equals("quit")) { 
       break; 
      } 

     System.out.println("Thank you for playing!"); 

     } 
    } 

    public static void printMenu() { 
     System.out.println(" * menu *"); 
     System.out.println("quit - quits the game"); 
     System.out.println("status - prints the game status"); 
     System.out.println("a single letter uses the letter as a guess"); 
     System.out.println("an empty line prints this menu"); 

    } 
} 
0

結束了丟失的項目資源。想要結束這件事。