Hello everyone.
I am completely lost with this assignment my professor gave us a few weeks ago. The due date has passed and I ended up submitting a basically blank code. However, I would still like to know how to do this. I just don't even know where to start. I think the multiple methods we have to use are confusion me. Here is what my professor wanted us to do:
Objective: Write a program that reads in lines from the input. For every line, it counts each letter of the English alphabet. It also counts the number of vowels, consonants, and others. It then prints out this information.You need to create and use and array that keeps track of the count for each letter.
Example input:
hevdhfewfewfe
hhwwrrr73##$6%&%7
Example output:
Line 01: d=1 e=4 f=3 h=2 v=1 w=2 YES vowels=4 consonants=9 others=0
Line 02: h=2 r=3 w=2 NO vowels=0 consonants=7 others=10
What to do:
1. You will need to declare a static int array variable that will keep track of the counts for each letter. This array should have length 26. Array Index 0 will be used to store count for the letter 'a'. Array Index 1 will be used to store count for the letter 'b'. Array Index 25 will be used to store count for the letter 'z'. Suppose the array is named letterCountArray. Then to access the index for character c, you will need to do c- 'a'. Thus, if c is 'm', your code will access index 'm' - 'a' - which is 12.
2. private static void addLetterCount(char c)
This method is to add to the count for the letter indicated by the variable c. Basically, index into the array declared above and add to the count for the letter indicated by variable c.
3. private static void zerroLetterCount()
Zero out all the elements of the array.
4. private static void printLetterCounts()
Loop over the array and print the counts for each letter. Thus, if there are only two counts that are not zero say 'a' has count 5 and 'z' has count 10, then this method will print "a=5 z=10 " (Note the space after 10).
5. private static int countVowels()
This method returns the sum of the count of all the vowels (i.e. for 'a', 'e', 'i'. 'o', 'u').
6. private static
String anyVowels()
This method returns the String 'NO" if countVowels() returns 0. Otherwise it returns the String "YES"
7. private static int countConsonants()
This method returns the sum of counts of all the consonants. (Just add all elements of the array and subtract countVowels().
8. private static void counts(int lineNum, String s)
This method is the "workhorse" of the program. It is given a line number and the line as input. It first loops over each character of the line and adds to the appropriate array element if it is a letter. Otherwise, it adds to "Other". Then it prints the information for the line as described earlier. To print the information, make use of the methods described earlier. Use printf with formal "Line%02d:" to be able to print the line number with LEADING zeroes.
9. main method.
In the main method, keep count of the line number and make calls to "counts" method as needed.
I know I don't have much but some guidance or any sort of help would be greatly appreciated.