Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2012
    Posts
    11
    Rep Power
    0

    Default flesch syllable counter

    im working on this one program that takes in a word/sentence and it returns the number of syllables that are in the word or sentence
    the problem is though that it isnt returning the correct number of syllables
    everytime i input something all i get is 0 syllables
    i am an absolute noob and havent learned debugging yet so someone please help me

    this method here will find out where all the words are by detecting spaces:
    Java Code:
          public int wordBreaker ()
          {
             String brokenFromSentence = "";
             int syllables = 0;
             char characterAtCurrentIndex = '\u0000';
          
             for (int indexNumber = 0; indexNumber <= word.length() - 1;indexNumber++)
             {
                characterAtCurrentIndex = word.charAt(indexNumber);
             
                if (characterAtCurrentIndex != ' ' || characterAtCurrentIndex != word.charAt(word.length() - 1))
                {
                   brokenFromSentence = brokenFromSentence.concat(new StringBuilder (characterAtCurrentIndex).toString());
                }
                
                else
                {
                   syllables += countSyllables(brokenFromSentence);
                   brokenFromSentence = "";
                }
             }
             
             return syllables;	
          }
    this method here is where a word is sent and syllables are found out:
    Java Code:
          public int countSyllables (String partOfAString)
          {
             char characterAtCurrentIndex = '\u0000';
             char characterAtPreviousIndex = '\u0000';
             int syllables = 0;
             
             for (int indexNumber = 0; indexNumber < partOfAString.length()-1; indexNumber++)
             {
                characterAtCurrentIndex = partOfAString.charAt(indexNumber);
             
                if (isVowel(characterAtCurrentIndex))
                {
                   characterAtPreviousIndex = characterAtCurrentIndex;
                }
                
                if (isVowel(characterAtPreviousIndex) == true &&
                    isVowel(characterAtCurrentIndex) == false)
                {
                   syllables++;
                   characterAtPreviousIndex = '\u0000';
                }
             }
          
             vowelsExceptE = "AIOUYaiouy";
          	
             if (vowelsExceptE.indexOf(partOfAString.charAt(partOfAString.length()-1)) != -1)
             {
                syllables++;
             } 
    
             if (syllables == 0)
             {
                syllables = 1;
             } 
    
             return syllables;
          }
    this method here detects all the vowels:
    Java Code:
          public static boolean isVowel (char ch)
          {
             vowels = "AEIOUYaeiouy";
             
             if (vowels.indexOf(ch) != -1 )
             {
                return true;
             }
             return false;
          }

    this is the test driver we are supposed to use:
    Java Code:
       import java.util.Scanner;
       import java.io.*;
    
       public class WordTester
       {
          public static void main(String [] args)throws IOException
          {
             Scanner reader = new Scanner(System.in);
          	
             System.out.print("Enter word/s: ");
             String input = reader.nextLine();
          	
             Word w = new Word(input);
          	
             System.out.println("Word = " + input);
             System.out.println("Syllables = " + w.wordBreaker());
          }
       }
    Last edited by sauronamaterasu13; 11-19-2012 at 01:15 AM.

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: flesch syllable counter

    i am an absolute noob and havent learned debugging yet so someone please help me
    So, now is a great time to learn. Your simplest form of debugging involves putting a bunch of System.out.println statements in your code to see how far execution progresses as well as the current state of any variables.

    I suggest you put some numbered printouts in your code so you can see where and when things happen, and then also print the state of your inputs and intermediate variables throughout your code. From that you should be able to deduce your logic errors!

Similar Threads

  1. word syllable program help
    By sauronamaterasu13 in forum New To Java
    Replies: 0
    Last Post: 11-16-2012, 12:28 AM
  2. Help with constructor counter.
    By lannie1980 in forum New To Java
    Replies: 3
    Last Post: 05-05-2012, 10:33 PM
  3. Counter problem
    By Razpet22 in forum NetBeans
    Replies: 5
    Last Post: 06-14-2011, 08:27 PM
  4. Counter
    By ks1615 in forum New To Java
    Replies: 6
    Last Post: 02-20-2009, 03:02 AM
  5. Help with Flesch Index
    By L_22 in forum Advanced Java
    Replies: 1
    Last Post: 03-31-2008, 05:30 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •