I wrote a flesch reading program that uses another class. I was under the impression that simply having the two classes saved in the same folder would enable one to access the other but I am getting errors. Any ideas.
The error I am getting is:
Flesch.java:36: cannot find symbol
symbol : method getSyllableCt()
location: class Flesch
sllyablesCt = getSyllableCt();
flesh is here:
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();
}
}
3 Answers 3
If the methods live in another class they need to either be (a) referenced as static methods, or (b) called on an instance of the class.
// Static method
int syllableCount = TheOtherClassName.getSyllableCt();
// Instance method
TheOtherClassName otherClass = new TheOtherClassName();
int syllableCount = otherClass.getSyllableCt();
However it's not clear where the methods in question live, or how they're getting their data.
Comments
if the method is in another class, you need to be make the class static.
ClassName.getSyllableCt();
Comments
sllyablesCt = getSyllableCt();
Your code has a typo. That variable doesn't exist. Change it to
syllablesCt = getSyllableCt();
4 Comments
symbol : method getSyllableCt() location: class Flesch.psvm, you're right.