COSC 60

advertisement
COSC 1020 – Lab 1 (Fall 2009)
Java Review
(1) Write a Java program that counts the number of vowels, consonants and spaces in a line of text.
The user will input a phrase (no punctuation) and you will count the number of vowels, consonants
and spaces in the text. You will also determine the total number of characters in the text. You will
output the results as shown in the example below.
The program will continue to ask for new input until the user presses the Enter key without first
entering text.
To simplify this calculation, the following rules will apply:
 only 'a', 'e', 'i', 'o' and 'u' will be counted as vowels
 the letters: 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z' will be
counted as consonants
 all input will be in lower case
 you can assume that no digits, punctuation or tab ('\t') characters will be in the user input
and that the input consists of only one line of text
 you are not required to include error checking (for example, to detect invalid characters).
Therefore, you only have to handle the letters 'a' to 'z' and the space character.
Hint: it would be easier to use the switch operation than to use a series of if...else operations.
Example Output:
System prompts are in bold letters, and user input is underlined.
java CountText
Enter a phrase: this is the first line of text
your input contains: 30 characters
including:
8 vowels
16 consonants
6 spaces
Enter a phrase: this is the last line entered into this program
your input contains: 47 characters
including:
14 vowels
25 consonants
8 spaces
Enter a phrase:
Bye
Note: Use Eclipse Java IDE to write your program.
Submission: Generate at least 3 test cases and show sample runs of your test cases to the TA.
Download