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)。配列リストのすべての要素を合計する部分がわかりません。

どうしたの?前もって感謝します :)

4

3 に答える 3

2

remove the semi-colon here.... public class WordSearchPuzzle;

this isn't a statement. puzzle[gridDimensions][gridDimensions];

puzzleWords.size(i).length in the for loop is giving issues. If you're wanting the number of elements in the list, puzzleWords.size() will work. And then letterCount = puzzleWords + letterCount ; , you have incompatible types, ArrayList + int, are you meaning to use puzzleWords.size() instead of puzzleWords?

于 2012-04-16T11:58:36.277 に答える
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ため、完全に削除できます。

于 2012-04-16T12:05:29.673 に答える
1

createPuzzleGrid では、For ループに 2 つの } があります

正しいバージョン:

private void createPuzzleGrid()
{
  int i;
    for(i = 0; i < puzzleWords.size(i).length ; i++){
      letterCount = puzzleWords + letterCount ;
    }
    gridDimensions = letterCount * 1.5;
    puzzle[gridDimensions][gridDimensions];
}
于 2012-04-16T11:55:56.327 に答える