Selection and Iteration unit test
A test on this unit alone, marked as a percentage and a letter grade — for the test your class is actually sitting, rather than for May. Answer everything, then submit once: seeing the answer to question 3 before attempting question 4 makes the final percentage meaningless.
break
Order of evaluation in a condition
Standard algorithm: determine if any element meets a condition
Converting for to while
Binary search
De Morgan's laws
Counting nested-loop iterations
Nested if
Compound boolean in a loop condition
Recursive method with an accumulating return
Logical OR
Infinite loop
Short answer 1. Define or explain: do-while loop
3 ptsShort answer 2. Define or explain: if / else
3 ptsShort answer 3. Define or explain: Binary search step count
3 ptsShort answer 4. Define or explain: Relational operators
3 ptsFree response
6 ptsThis course has no free-response prompt tagged to this unit, so one from elsewhere in the course is used. It is still worth writing — the skill transfers.
Write a static method countVowels that takes a String and returns the number of vowels (a, e, i, o, u) it contains, counting both uppercase and lowercase letters. Then write a static method vowelPercent that returns the percentage of characters in the string that are vowels, as a double, returning 0.0 for an empty string. You may call countVowels from vowelPercent. public static int countVowels(String s) public static double vowelPercent(String s) For example, countVowels("Apple Pie") returns 4 and vowelPercent("Apple Pie") returns approximately 44.4.