Results 1 to 2 of 2
Thread: flesch syllable counter
- 11-19-2012, 01:08 AM #1
Member
- Join Date
- Aug 2012
- Posts
- 11
- Rep Power
- 0
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:
this method here is where a word is sent and syllables are found out: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 detects all the vowels: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; }
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.
- 11-20-2012, 08:25 PM #2
Re: flesch syllable counter
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 am an absolute noob and havent learned debugging yet so someone please help me
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
-
word syllable program help
By sauronamaterasu13 in forum New To JavaReplies: 0Last Post: 11-16-2012, 12:28 AM -
Help with constructor counter.
By lannie1980 in forum New To JavaReplies: 3Last Post: 05-05-2012, 10:33 PM -
Counter problem
By Razpet22 in forum NetBeansReplies: 5Last Post: 06-14-2011, 08:27 PM -
Counter
By ks1615 in forum New To JavaReplies: 6Last Post: 02-20-2009, 03:02 AM -
Help with Flesch Index
By L_22 in forum Advanced JavaReplies: 1Last Post: 03-31-2008, 05:30 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks