Unit 2: Selection and Iteration
CS A · Unit 2 · Paper 2

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.

Each paper is built from this unit’s 53 terms and is the same for everyone, so a teacher can assign “Unit 2, Paper 2” and every student sits the identical test. Multiple choice is marked objectively; the written sections you mark yourself against the model answer and rubric.
Suggested time 33 min 30 points0/17 attempted
1

break

2

Order of evaluation in a condition

3

Standard algorithm: determine if any element meets a condition

4

Converting for to while

5

Binary search

6

De Morgan's laws

7

Counting nested-loop iterations

8

Nested if

9

Compound boolean in a loop condition

10

Recursive method with an accumulating return

11

Logical OR

12

Infinite loop

Short answer 1. Define or explain: do-while loop

3 pts

Short answer 2. Define or explain: if / else

3 pts

Short answer 3. Define or explain: Binary search step count

3 pts

Short answer 4. Define or explain: Relational operators

3 pts

Free response

6 pts

This 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.