Write a program called SyllableCounter
which estimates the number of syllables in each input word using
the following rules:
'a', 'e', 'i', 'o', 'u', and 'y' are always counted as vowels.
Each
group of adjacent vowels counts as one syllable. For example, the
"ea" in "real" counts as one syllable, but the "ega" in "regal"
counts as two syllables.
However, an 'e' at the end of the word
doesn't count as a syllable.
Also, each word has at least one syllable, even if the previous
rules give a count of 0.
Sample words and their syllable counts (using the rules above):
Example word
Expected syllable count
a
1
oi
1
hi
1
try
1
regal
2
real
1
grotto
2
late
1
supercalifragilisticexpialidocious
13
hmmm
1
be
1
Your program should read words from the keyboard (or a file, see
below) one
at a time.
Print each word and its expected
syllable count on a separate line.
Optional:
Read the input words from a
file (the file wordList.txt contains all of
the sample words above) instead of making the user type them in. This
involves three steps:
import
java.io.*;
add a throws clause to the main method like this: public
static void main(String[] args) throws
FileNotFoundException {
create a Scanner object on the file wordList.txt like this: Scanner
fileScan = new Scanner(new File("wordList.txt"));
- fileScan now reads from the file wordList.txt, rather than
the keyboard. (Make sure that the input file is in the same directory
as the program)
- there is no need to prompt the user since they don't have to
type
anything
Sample output:
a 1
oi 1
hi 1
try 1
regal 2
real 1
grotto 2
late 1
supercalifragilisticexpialidocious 13
hmmm 1
be 1
Submit the following file to Anne (javaiscl (at googlemail.com)):
SyllableCounter.java