Open a file and count vowels

M

Matt

I am trying to create a program which will allow the user to open there
desired text file and count the number of Vowels, and lines in the
text. As of yet i cant find or dont know how to produce this program. I
need to use Java was wondering if anyone has any ideas.
 
C

Christopher Benson-Manica

Matt said:
I am trying to create a program which will allow the user to open there
desired text file and count the number of Vowels, and lines in the
text. As of yet i cant find or dont know how to produce this program. I
need to use Java was wondering if anyone has any ideas.

Use the classes and methods in the java.io package to open the file.
Your friendly Java reference can tell you more. Read each line. Keep
count. Look at each character and see if it's a vowel. Keep count.

It should be beyond trivial for you to demonstrate 0.00001% effort and
1) use Google as a source of information, 2) read your friendly
textbook, and 3) try it yourself.
 
D

Daniel Pitts

Christopher said:
Use the classes and methods in the java.io package to open the file.
Your friendly Java reference can tell you more. Read each line. Keep
count. Look at each character and see if it's a vowel. Keep count.

It should be beyond trivial for you to demonstrate 0.00001% effort and
1) use Google as a source of information, 2) read your friendly
textbook, and 3) try it yourself.
4) pay attention in class :)
 
R

Rhino

Matt said:
I am trying to create a program which will allow the user to open there
desired text file and count the number of Vowels, and lines in the
text. As of yet i cant find or dont know how to produce this program. I
need to use Java was wondering if anyone has any ideas.

You didn't mention what language the text file is using and that could make
a difference. I'm not talking about the programming language which you are
using to parse the text file, I'm talking about the language used in the
text file.

Even if the language used in the text file is always English and you _know_
that it is always English, what do you do with the letter "y"? Is it a vowel
or a consonant? When I was in primary school, they taught that the vowels
were "a, e, i, o, u and _sometimes_ y". (I don't remember anyone ever
explaining when 'y' was considered a vowel and when it was considered a
consonant so I _suspect_ that the 'y' in "happy" is considered a vowel but
the 'y' in "yard" is considered a consonant without really being remotely
SURE.)

If the language in the text file isn't guaranteed to be English, the problem
gets much harder since you presumably don't know which language it is. And
while many languages are written using the same letters that we use in
English - sometimes with accents thrown in - those letters aren't always
pronounced the same as we pronounce them. So, in some cases, a letter that
might be a vowel to us could conceivably be a consonant in the other
language. (I can't actually think of an example of 'a', 'e', 'i', 'o' or 'u'
being considered a consonant in some other language but it seems possible
that such a case could exist.) And once you get into languages that don't
use the English alphabet - like Russian or Chinese - things get even
crazier. I'm pretty sure Russian has letters that are considered vowels -
although I'm not sure which ones they are - but I'm not at all sure if
Chinese or Arabic or Hindi even has the concept of vowels and consonants.

Now, I'm probably just overcomplicating the problem far beyond the
intentions of your instructor but, if you are hoping to do a thorough job
with this program, you may want to research this point and see if the
definition of a vowel is sufficiently firm that you can apply it to any
language you find in the text file that you are parsing. This could be worth
serious brownie points if you can actually handle a multitude of languages
and recognize the vowels in them regardless of the language chosen. :)
 
K

Karl Uppiano

Rhino said:
You didn't mention what language the text file is using and that could
make a difference. I'm not talking about the programming language which
you are using to parse the text file, I'm talking about the language used
in the text file.

Even if the language used in the text file is always English and you
_know_ that it is always English, what do you do with the letter "y"? Is
it a vowel or a consonant? When I was in primary school, they taught that
the vowels were "a, e, i, o, u and _sometimes_ y". (I don't remember
anyone ever explaining when 'y' was considered a vowel and when it was
considered a consonant so I _suspect_ that the 'y' in "happy" is
considered a vowel but the 'y' in "yard" is considered a consonant without
really being remotely SURE.)

If the language in the text file isn't guaranteed to be English, the
problem gets much harder since you presumably don't know which language it
is. And while many languages are written using the same letters that we
use in English - sometimes with accents thrown in - those letters aren't
always pronounced the same as we pronounce them. So, in some cases, a
letter that might be a vowel to us could conceivably be a consonant in the
other language. (I can't actually think of an example of 'a', 'e', 'i',
'o' or 'u' being considered a consonant in some other language but it
seems possible that such a case could exist.) And once you get into
languages that don't use the English alphabet - like Russian or Chinese -
things get even crazier. I'm pretty sure Russian has letters that are
considered vowels - although I'm not sure which ones they are - but I'm
not at all sure if Chinese or Arabic or Hindi even has the concept of
vowels and consonants.

Now, I'm probably just overcomplicating the problem far beyond the
intentions of your instructor but, if you are hoping to do a thorough job
with this program, you may want to research this point and see if the
definition of a vowel is sufficiently firm that you can apply it to any
language you find in the text file that you are parsing. This could be
worth serious brownie points if you can actually handle a multitude of
languages and recognize the vowels in them regardless of the language
chosen. :)

I thought Character.isVowel was localized! Ha ha ha!

Man, I crack myself up...
 
O

Oliver Wong

[context is counting vowels in a text file]

Rhino said:
Even if the language used in the text file is always English and you
_know_ that it is always English, what do you do with the letter "y"? Is
it a vowel or a consonant? When I was in primary school, they taught that
the vowels were "a, e, i, o, u and _sometimes_ y". (I don't remember
anyone ever explaining when 'y' was considered a vowel and when it was
considered a consonant so I _suspect_ that the 'y' in "happy" is
considered a vowel but the 'y' in "yard" is considered a consonant without
really being remotely SURE.)

If the language in the text file isn't guaranteed to be English, the
problem gets much harder since you presumably don't know which language it
is. And while many languages are written using the same letters that we
use in English - sometimes with accents thrown in - those letters aren't
always pronounced the same as we pronounce them. So, in some cases, a
letter that might be a vowel to us could conceivably be a consonant in the
other language. (I can't actually think of an example of 'a', 'e', 'i',
'o' or 'u' being considered a consonant in some other language but it
seems possible that such a case could exist.) And once you get into
languages that don't use the English alphabet - like Russian or Chinese -
things get even crazier. I'm pretty sure Russian has letters that are
considered vowels - although I'm not sure which ones they are - but I'm
not at all sure if Chinese or Arabic or Hindi even has the concept of
vowels and consonants.

According to Wikipedia, it should be not be said that a given letter or
character is or is not a vowel, but rather a given *sound* may or may not be
a vowel. So as you point out, the letter 'y' maps onto different sounds,
depending on the surrounding letters, and in some cases, the sound it maps
onto happens to be a vowel, and in other cases, the sound it maps onto
happens to not be a vowel. The definition Wikipedia gives is "a vowel is a
sound in spoken language that is characterized by an open configuration of
the vocal tract so that there is no build-up of air pressure above the
glottis.".

So for example, the word "beet" contains a single vowel, represented by
the sequence of characters "ee", as opposed to containing two vowels. And
"W" is a vowel in Welsh, as is "V" in Creek. And if you had an arbitrary
stream of characters, for which the pronounciation was not well defined,
would it even be meaningful to ask about the number of vowels within that
stream? Does "QREA" contain one vowel, or two, or three, something else? It
probably depends on whether I, as the inventor of this word, declare its
pronounciation to be "Kwri", or "Kree Ah" or "Ku Wree Ay" or something else.

If this is a school assignment (and the subject under study is *not*
linguistics), then I'd assume the teacher simply wants the student to count
the number of occurrences of the letters "a", "e", "i", "o", "u"; And
whether or not "y" should be included would be clarified by the teacher.

- Oliver
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top