Lab 05: 09/28/2006

advertisement
Lab 3
COSC 61
(I) Write a program (TestValues.java) that accepts an argument: (i) values.txt file that
contains a list of integer values. The program then outputs the total sum, and each value
along with what percentage it contributes to the sum.
A sample run is given below:
java TestValues values.txt
The sum of the numbers = 6
Here are the numbers and their percent contribution to the sum.
2
1
1
2
is
is
is
is
33%
17%
17%
33%
of
of
of
of
the
the
the
the
sum.
sum.
sum.
sum.
For the above run, assume values.txt contents are as follows:
values.txt
2
1
1
2
(II) You will write a Java program that counts the number of vowels, consonants and
spaces in a line of text.
Save the file as CountText.java
Requirements:
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.
Note that 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:
Note: text in italic font indicates user input.
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:
Download