gpt4 book ai didi

java - 类问题java

转载 作者:行者123 更新时间:2023-11-29 07:18:02 25 4
gpt4 key购买 nike

我写了一个使用另一个类的 flesch 阅读程序。我的印象是,只要将两个类保存在同一个文件夹中就可以让一个类访问另一个类,但我遇到了错误。任何想法。

我得到的错误是:

Flesch.java:36: cannot find symbol
symbol : method getSyllableCt()
location: class Flesch
sllyablesCt = getSyllableCt();

肉在这里:

public class Flesch{

public static void main(String args[])throws Exception{
int syllablesCt,
wordCt,
sentenceCt;
double flesch;

String listStr;
StringBuffer sb = new StringBuffer();

String inputFile = JOptionPane.showInputDialog("What file do you want to sort?");

BufferedReader inFile = new BufferedReader(new FileReader(inputFile));

sb.append(inFile.readLine());

//listStr = inFile.readLine();
while (inFile.readLine() != null){

sb.append(inFile.readLine());
//listStr = inFile.readLine();

}


Sentence sentence = new Sentence(sb);
wordCt = getWordCt();
sentenceCt = getSentenceCt();
System.out.println("The sentence count is" + sentenceCt);
System.out.println("The word count is" + wordCt());
Word word = new Word(getWords());

sllyablesCt = getSyllableCt();
System.out.println("The syllable count is" + syllablesCt);

flesch = (.39 * wordCt / sentenceCt) + (11.8 * syllablesCt / wordCt) - 15.59;
System.out.println("The Flesch Readability of this document is" + flesch);

inFile.close();
}
}

最佳答案

如果这些方法存在于另一个类中,则它们需要 (a) 作为静态方法被引用,或 (b) 在该类的实例上调用。

// Static method
int syllableCount = TheOtherClassName.getSyllableCt();

// Instance method
TheOtherClassName otherClass = new TheOtherClassName();
int syllableCount = otherClass.getSyllableCt();

但是,尚不清楚相关方法存在于何处,或者它们如何获取数据。

关于java - 类问题java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7854325/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com