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)。我不确定将数组列表的所有元素加在一起的部分。
这是怎么回事?提前致谢 :)