Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Flesch Readability Index Code

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Location
    Atlanta
    Posts
    3
    My Mood
    Worried
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Flesch Readability Index Code

    Hey, I'm writing a program about the Flesch Readability Index that is supposed to calculate the number or words, syllables, and sentences in a file. I have gotten the words counter to work, but I'm having a little difficulty with the syllables. The file I'm testing with just states "These cats are fast.", but I'm not getting a syllable count of 4. Hope you can help me figure this out! ^^

    //count syllables; each group of adjacent vowels is one syllable; regal would be 2
    //vowels = a,e,i,o,u,y
    //e at end of word is not a vowel
    //each word has at least one syllable
    //sentence = ends by ., :, ;, ?, or !
    //index is computed by Index = 206.835 - 84.6*(num of syll/num of words) - 1.015*(num of words/num of sent)
    //rounded to nearest int
    //read file, compute index, print out educational level
     
    import java.io.*;
    import javax.swing.JFileChooser;
    import java.util.Scanner;
     
    public class Flesch
    {
    public static void main (String [] args) throws IOException
    {
    File datafile = null;
    JFileChooser chooser = new JFileChooser();
    FileReader reader = null;
    String input = "";
    String [] words;
     
    if(chooser.showOpenDialog(null)==JFileChooser.APPROVE_OPTION)
    datafile =chooser.getSelectedFile();
     
     
    Scanner in = new Scanner(new FileReader(datafile)); 
     
    String content = in.nextLine();
    int totalWords = 0;
    int totalSyll = 0;
     
    //WORDS
    for (int i=0; i<content.length(); i++)
    {
    if (content.charAt(i)==' ')
    totalWords++;
    else if (content.charAt(i) == '.')
    totalWords++;
    else if (content.charAt(i) == ':')
    totalWords++;
    else if (content.charAt(i) == ';')
    totalWords++;
    else if (content.charAt(i) == '?')
    totalWords++;
    else if (content.charAt(i) == '!')
    totalWords++;
    else
    totalWords=totalWords;
    }
    System.out.println("There are " + totalWords + " words.");
     
    char syllableArray [] = {'a','e','i','o','u','y'};
     
    //SYLLABLES
    for (int k=0; k<syllableArray.length; k++)
    {
    for (int i=0; i<=content.length(); i++)
    {
    if (content.charAt(i) == syllableArray[k] & content.charAt(i) == syllableArray[k])
    totalSyll=totalSyll;
    if (content.charAt(i) == syllableArray[1]+' ')
    totalSyll=totalSyll;
    if (content.charAt(i) == syllableArray[k])
    totalSyll++;
    else
    totalSyll=totalSyll;
    }
    }
     
    System.out.println("There are "+ totalSyll + " syllables.");
    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,101
    Thanks
    52
    Thanked 2,285 Times in 2,256 Posts

    Default Re: Flesch Readability Index Code

    'm not getting a syllable count of 4.
    What count are you getting?
    What is your logic/algorithm for finding syllables?

  3. #3
    Junior Member
    Join Date
    Dec 2011
    Location
    Atlanta
    Posts
    3
    My Mood
    Worried
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Flesch Readability Index Code

    I'm getting an Out Of Bounds Exception error, so I know somewhere either the int i or the int k is getting to be too high (probably off by one) with their increment operators, so they access any more, because there's nothing to access.

    The logic I was using that if a word ends in 'e', then that isn't a syllable, so I put if it ends in 'e' and then there's white space ' ' then the total number of syllables stays the same. If a word has 2 vowels next to each other, that isn't considered a vowel either. But the only part I"m having trouble with the out of bounds exception error, I"m not sure where it's coming from.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,101
    Thanks
    52
    Thanked 2,285 Times in 2,256 Posts

    Default Re: Flesch Readability Index Code

    getting an Out Of Bounds Exception error
    Please post the full text of the error message. It will have the line number and the value of the index.

    Look at the size of the array and compare it to the value of the index in the error message.
    Remember: that indexes start at 0. The max index is the length of the array -1.

  5. The Following User Says Thank You to Norm For This Useful Post:

    fakeviolist (December 15th, 2011)

  6. #5
    Junior Member
    Join Date
    Dec 2011
    Location
    Atlanta
    Posts
    3
    My Mood
    Worried
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Flesch Readability Index Code

    Oh, I got it. In my for loops, I made sure that the variables i and k couldn't equal the number of indices, but I didn't realize that the increment operator would make them one higher. I fixed it by adding minus one to both of the for loops. Thank you for the advice! ^^

Similar Threads

  1. Need help with index of coincedence
    By tripline in forum Java Theory & Questions
    Replies: 4
    Last Post: October 30th, 2011, 11:29 AM
  2. Array index out of bounds
    By fortune2k in forum Collections and Generics
    Replies: 1
    Last Post: November 30th, 2010, 06:11 AM
  3. String Index out of range
    By petemyster in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 8th, 2010, 02:59 PM
  4. index of array
    By nasi in forum Java Theory & Questions
    Replies: 1
    Last Post: April 12th, 2010, 02:39 AM
  5. Index Out Of Bounds
    By chronoz13 in forum Collections and Generics
    Replies: 1
    Last Post: December 28th, 2009, 11:19 AM

Tags for this Thread