我正在尝试创建一个处理文件导入的每个单词的 Word 类。
Word Class 需要区分句子的结尾/开头的标点符号,增加有效单词,并增加每个音节。
我的问题是让扫描仪将单词传递给 Word 类,以便处理它们的方法。错误出现在“word = scan.next();。” 错误消息是“不兼容的类型:必需的单词,找到的字符串”。
谢谢您的帮助...
System.out.println("You chose to open the file: " +
fc.getSelectedFile().getName());
scan = new Scanner(fc.getSelectedFile());
while (scan.hasNext())
{
Word word = new Word();
word = scan.next();
词类
public class Word {
private int wordCount, syllableCount, sentenceCount;
private double index;
private char syllables [] = {'a', 'e', 'i', 'o', 'u', 'y'};;
private char punctuation [] = {'!', '?','.'};;
public Word()
{
wordCount = 0;
syllableCount = 0;
sentenceCount = 0;
}
public void Word(String word)
{
if(word.length() > 1)
{
for(int i=0; i < punctuation.length; i++)
{
if(punctuation[i] != word.charAt(word.length()-1))
{
wordCount++;
}
else
sentenceCount++;
}
for(int i = 0; i < syllables.length; i++)
{
for(int j = 0; j < word.length(); j++)
{
if(syllables[i] == word.charAt(j))
{
syllableCount++;
}
}
}
}
System.out.println(word);
}
}