Assignment 14
Due Tuesday, June 2 at 11:59pm on Canvas
Important: To receive credit, you must only use concepts and methods taught in class to complete these assignments - or you will receive a 0
Pair Programming Required (or You Will Receive a 0)
- Both partners fill in, sign, date, and submit the pair programming contract
- Upload the document(s) along with your assignment code to Canvas.
- No extra credit if you do not submit the contract along with your code to Canvas
- Please make sure both your names are on your file (hint: use a comment).
- If you need help finding a partner, please contact me as soon as possible.
Assignment 14: Vowels, Capitals and Digits (10 pts)
- Write
a program that prompts the user for a sentence and then calculates the
total number of vowels and the total number of capital letters in the
sentence, and reports if there are any numerical digits in the sentence.
- Save your program as VowCapDig.java.
- The program should run using an indefinite loop (of your choice) to allow the user to enter as many sentences as desired.
- The program must contain the following methods (in addition to main):
Vowel Counter: - This method must be named vowelCounter
- It takes a String parameter
- It returns an int for the total number of vowels (A, E, I, O, U, a, e, i, o, u) contained in the String
Capital Counter: - This method must be named capitalCounter
- It takes a String parameter
- It returns an int for the total number of capital letters contained in the String
Contains Digit: - This method must be named containsDigit
- It takes a String parameter
- It returns a boolean for whether there are any numerical digits (0-9) contained in the String
- Hint: all of these methods should use a for loop to iterate the String searching for vowels, capital letters or digits
- Recall that you can use an if statement with <= and >= to compare characters
- Also, the Unicode
table may be helpful here. Note that the digits fall within a defined
range of Unicode values. Capital letters also fall within a defined
range of Unicode values.
- Write your indefinite loop in main and call your methods inside of this indefinite loop.
- Note the " around the q in the prompt.
- Your program must work identically to the sample output below for full credit.
Sample Output:
Welcome!
Enter a sentence or "q" to quit: Power to the people!
There are 7 vowel(s) in the sentence. There are 1 capital letter(s).
The sentence does not contain digits.
Enter a sentence or "q" to quit: 256 E. Elm St, San Jose
There are 5 vowel(s) in the sentence.
There are 5 capital letter(s).
The sentence does contain digits.
Enter a sentence or "q" to quit: Eleanor Roosevelt
There are 8 vowel(s) in the sentence. There are 2 capital letter(s).
The sentence does not contain digits.
Enter a sentence or "q" to quit: q
Goodbye!
- When you are certain VowCapDig.java is working properly submit it to Canvas.
|
|