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
9 ptsMETHODS AND CONTROL STRUCTURES (Question 1, 9 points). The Account class represents a website user account with a private String username. A provided static helper, boolean isAvailable(String str), returns whether a username is available. You will write: public Account(String requestedName) — if requestedName is available, assign it to username; otherwise try requestedName followed by successive integers starting at 1 ("Luis-Cruz1", "Luis-Cruz2", …) until an available variation is found, and assign the first available one. public String getShortenedName() — returns a shortened copy of username with each hyphen AND the character immediately before it removed (username never starts or ends with a hyphen, has no consecutive hyphens, and has length ≥ 2; username itself is unchanged). Examples: "Amy-Marie-Lin" → "AmMariLin"; "SammyB3" → "SammyB3".
A. Complete the Account constructor. You must use isAvailable appropriately to receive full credit.
B. Complete method getShortenedName.