1

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();
}
}
0

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

Comments

1

if the method is in another class, you need to be make the class static.

ClassName.getSyllableCt();

Comments

1
sllyablesCt = getSyllableCt();

Your code has a typo. That variable doesn't exist. Change it to

syllablesCt = getSyllableCt();

4 Comments

True, though the message says symbol : method getSyllableCt() location: class Flesch.
Yes I understand that. However it's best to fix all errors to make sure you're debugger is giving the correct error report. There isn't an error being thrown getSentenceCT() which may be in another class file?
@Dave - If its a static error, the message usually states the need for a static method. This seems more like a typo error.
@Spidy Not if the method is in another class, then it'd just say it can't be located, because it doesn't know where to look. But yep, if the method name is misspelled, and it's in the same class, and it's accessible by the psvm, you're right.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.