2012-04-16 9 views
1
import java.io.* ; 
import java.util.ArrayList ; 
public class WordSearchPuzzle; 
{ 
    private char[][] puzzle ; 
    private ArrayList<String> puzzleWords ; 
    private int letterCount = 0 ; 
    private int gridDimensions; 

    public WordSearchPuzzle(ArrayList<String> userSpecifiedWords) 
    { 
     this.puzzleWords = userSpecifiedWords ; 

    } 
    private void createPuzzleGrid() 
    { 
     int i; 
     for(i = 0; i < puzzleWords.size(i).length ; i++){ 
      letterCount = puzzleWords + letterCount ; 
      } 
     } 
     gridDimensions = letterCount * 1.5; 
     puzzle[gridDimensions][gridDimensions]; 
    } 

    public WordSearchPuzzle(String wordFile, int wordCount, 
    int shortest, int longest) 
    { 
     // puzzle generation using words from a file 
     // The user supplies the filename. In the file 
     // the words should appear one per line. 
     // The wordCount specifies the number of words 
     // to (randomly) select from the file for use in 
     // the puzzle. 
     // shortest and longest specify the shortest 
     // word length to be used and longest specifies 
     // the longest word length to be used. 
     // SO, using the words in the file randomly select 
     // wordCount words with lengths between shortest 
     // and longest. 

    } 

    private ArrayList<String> loadWordsFromFile(String filename, int shortest, int longest) 
    { 
     // BasicEnglish.txt - the 850 words of Basic English 
     // BNCwords.txt - "the 6,318 words with more than 800 occurrences in 
     //the whole 100M-word BNC" 
     try { 
      FileReader aFileReader = new FileReader(filename); 
      BufferedReader aBufferReader = new BufferedReader(aFileReader); 
      String lineFromFile; 
      int len ; 
      ArrayList<String> words = new ArrayList<String>(); 
      lineFromFile = aBufferReader.readLine() ; 
      while (lineFromFile != null) { 
       len = lineFromFile.length() ; 
       if(len >= shortest && len <= longest) { 
        words.add(lineFromFile.toUpperCase()); 
       } 
       lineFromFile = aBufferReader.readLine() ; 
      } 
      aBufferReader.close(); 
      aFileReader.close(); 
      return words ; 
     } 
     catch(IOException x) 
     { 
      return null ; 
     } 
    } 

    // The dimensions of the puzzle grid should be set 
    // by summing the lengths of the words being used in the 
    // puzzle and multiplying the sum by 1.5 or 1.75 
    // or some other (appropriate) scaling factor to 
    // ensure that the grid will have enough additional 
    // characters to obscure the puzzle words. Once 
    // you have calculated how many characters you are 
    // going to have in the grid you can calculate the 
    // grid dimensions by getting the square root (rounded up) 
    // of the character total. 
} 

こんにちは、小さなJavaプロジェクト私はここで大学で行う必要があります。ここまで私がこれまで持っていたことがあります。なぜそれがコンパイルされていないのか分かりません。グリッドを生成するためのコードがあります。グリッドの寸法は入力単語(すべての入力単語の文字の合計* 1.5)によって設定されます。私は、Array Listのすべての要素をまとめた部分についてはわかりません。arrayList内の文字数をカウントするのに役立つ必要があります

何が起こっているのですか?事前に感謝:)あなたcreatePuzzleGridで

+2

コンパイラにはどのようなエラーがありますか? – luketorjussen

答えて

1

は、二人はあなたのために、ループ

correctecバージョンに}があります:

private void createPuzzleGrid() 
{ 
    int i; 
    for(i = 0; i < puzzleWords.size(i).length ; i++){ 
     letterCount = puzzleWords + letterCount ; 
    } 
    gridDimensions = letterCount * 1.5; 
    puzzle[gridDimensions][gridDimensions]; 
} 
2

....ここpublic class WordSearchPuzzle;

をセミコロンを削除

これは声明ではありません。 puzzle[gridDimensions][gridDimensions];

puzzleWords.size(i).length forループで問題が発生しています。リスト内の要素の数を希望する場合は、puzzleWords.size()が機能します。そしてletterCount = puzzleWords + letterCount ; 、あなたは互換性のない型、ArrayList + intを持っていますか?あなたはpuzzleWordsの代わりにpuzzleWords.size()を使用することを意味していますか?

+0

ありがとうございました! – User123Rocks

2

私は複数の問題を見ることができます:クラス宣言行で

を一切セミコロンがあってはなりません。

public class WordSearchPuzzle 

Nettogrofが示しているように、あなたはあまりにも多くの}をcreatePuzzleGridメソッドに持っています。

createPuzzleGrid内のループは、存在しないメソッドを使用します。 配列リストのパラメータを取る方法はありません。sizeまた、それはその時点での文字列の長さを見つけることができません createPuzzleGridであなたのループは次のようになります。余分な注意点としては

for (int i = 0; i < puzzleWords.size; i++) { 
    String item = puzzleWords.get(i); 
    int itemLength = item.length(); 
    letterCount = letterCount + itemLength; 
} 

、そのメソッドの最後の行は、そう、puzzle配列にアクセスするが、何もしませんこの行を削除することができます。実際、メソッドは変数puzzleを使用しないため、完全に削除することはできません。

関連する問題