College Board 2014 Corrections
Q10 seqSearchRec with int array test - Topic 10.1
Answer B – II only
Choice I will return the correct value if the element in the array with one element was target. In this case, with the first call to seqSearchRecHelper the value of data[0] would be target and 0 would be returned. Choice II will eventually cause an ArrayIndexOutOfBoundsException to be thrown when the recursive call is made with target and -1. This will happen after every valid index in data has been examined. During this call, data[-1] is out of bounds. Choice III will correctly return the index of the element closest to the end of the array with the value target, since data[last] == target will be true at some valid index value of last.
Q14 Vehicle interface getMileage – Topic 7.2/7.4
Answer E – v.getMileage ()
The algorithm is using an enhanced for loop to access each element in the myVehicles ArrayList. The Vehicle object v is assigned each element, one at a time during the iterations of the enhanced for loop. To access the mileage for each Vehicle, the getMileage method in Vehicle needs to be called on the object. This is accomplished the same way for interfaces as with other classes. The dot operator is used along with the object name to call non-static methods using the form object.method(parameters). The getMileage method does not have any parameters, so v.getMileage() will return the mileage for v. Please note that interface is no longer a part of the AP CSA exam.
Q19 Compound expression using 7 and variables a, b – Topic 3.6
**Answer B – (a!=b) | (b<=7)** |
De Morgan’s Law states that !(p && q) is equivalent to !p | !q. By applying De Morgan’s Law to this expression, we negate the first expression !(!(a !=b)) and the second expression !(b >7) to form !(!(a != b)) | !(b > 7). In the first expression the two consecutive not operators (!) cancel each other out giving us (a != b). In the second expression, the opposite of > is <= giving us (b <= 7). The equivalent expression is (a != b) | (b <= 7). |