College Board Corrections

Screenshot 2023-12-22 at 9 21 04 AM

Question 4

The answer is C. The largest value in arr is negative.

This is because the code initializes the maxVal to zero. If all numbers in the array are zero since the check is for > maxVal, which is zero it will never set maxVal for a negative number. Thus maxVal will remain zero passing through the entire loop.

Question 9

The answer is E

The Math.random() returns a value between 0.0 and 1.0. That is multiplied by 6 to give you a value of 1-6. Multiply that *2 and that gives you a max of 12.

Question 26

The answer is E

No class instance variables here. They are all in the start method. They only exist in the scope of the start method.

Only print statements are in the start method and the signature on the “changeIt” method is a void return. This shows that while the nums variable, value variable and name variable = “blackboard” is passed in there is no modification of those variables in “changeIt”.

not a, c, d : no modification of “name” after it is defined at the top of the start method. All lines below that in the start method simply print out the variables. The nums array is printed, then the value of the value variable then the value of the name variable.

None of variables in the start method are modified after they are defined. They are just printed out.

Question 30

The answer is B

Code chunk I does not work because every “if” statement will be checked.

Code chunk II does work because the code uses “if” and “if else” statements. It starts with the condition for the highest number range first then goes down.

Code chunk III does not work because the first if statement simply does > 0. That will take all counts > 0 and apply the $5 a box price range which is incorrect.

Question 36

The answer is D

Code starts out with a while loop with conditions using “start” and “end” variables. Array starts at zero and ends at last slot (data.length -1).

The variable “mid” is calculated as (1 + 8) / 2 = 3 for the first pass of the while loop. Target is greater than value at mid slot (i.e. “4”) so end = mid + 1. Recalculate the “mid” variable as (2 + 8) / 2 = 5. Target is equal to the value at mid slot (i.e. “8”) so we have a hit on the search. Code returns the slot where the middle variable is, which is 5.

Question 38

The answer is C

The first “if” block in the code checks to see if there is a match of the search variable (i.e. “v”) to the last variable in the array (as indicated by numVals - 1). Note that because this is recursive each call to mystery will back up this up one lower in the array. The second “if” block checks to see if the array is only one long. If that’s the case, return and end. There is no more to process in the array. The else of the second “if” block calls mystery again, but this time sets the numVals length one shorter. The mystery method runs again. If there is a match (i.e. first “if” block is true), k = 1 meaning that when the stack unwinds 1 will be added to the overall return value.

Reflection

  • reread questions more often becuase college board has tricky wording
  • less distracted while taking the test
  • be careful and make sure the answer is correct before moving onto the next question
  • try to not run the code block when confused
  • guess on questions less