Main Takeaways

  • need to work on arrays and classes notation
  • on actual test, use pencil and paper to keep track of large sets of datas when dealing with an array problem. I got mixed up handling so many numbers all in my head at once
  • don’t get indexes of arrays confused. Index for java starts at zero. data.length is one more than the last index value (also applies to list.size).
  • data[k] changes after each iteration
  • private variables cannot be accessed from outside the class

Corrections

  • #15 (A) : For choice II, the data.length upper bound will cause and out of bounds error when inserted into data[data.length-1] and data[data.length-1+1]. But for choice I and II, data[k-1]>datadata[k] and data[k]> data[k+1] both correctly check that if the values are decreasing or not.
  • #18 (B) : The indices for myList are 0 through myList.size() – 1, for a total of myList.size() elements. Using Math.random()generates a random floating point number between 0 and 1, not including 1. When this value is multiplied by the number of elements we want in our range, myList.size(), a random floating point number between 0 and myList.size(), not including myList.size(), is generated. When this value is typecast as an int, the result is an integer value between 0 and myList.size() – 1 inclusive.
  • #29 (E) : The original code segment prints all values between 1 and 100 that are evenly divisible by 4. The following values are printed: 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80, 84, 88, 92, 96, and 100. Choice E shows these values can also be printed by having a for loop that has a loop control variable k that starts at 4, increments by 4, and terminates when k is greater than 100.
  • #31 (C) : Data[K+1] being added to Data[K], adding values in array to each other. For every single iteration of the loop, data[K+1] is updated so values are only increasing. So you aren’t just adding 2 numbers next to each other. Add the new number each time.
  • #34 (B) : Choice 2 correctly creates a new point with the two paramerter Point constructor that assigns a to x and b to y. Choice 1 and 3 use the no paramater point constructor which incorrectly assigns 0 to both x and y. Choice 3 attempts to update x and y individually but they are variables in Point that cannot be accessed direclty from circle. This code will cause a compile runtime error.