Daniel Campbell
Daniel Campbell

Reputation: 71

Class issue java

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

Upvotes: 1

Views: 162

Answers (3)

Dave Newton
Dave Newton

Reputation: 160291

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.

Upvotes: 4

Tyler Ferraro
Tyler Ferraro

Reputation: 3772

sllyablesCt = getSyllableCt();

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

syllablesCt = getSyllableCt();

Upvotes: 1

denniss
denniss

Reputation: 17629

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

ClassName.getSyllableCt();

Upvotes: 1

Related Questions