Final Blog
What I got wrong, what I learned, and N@TM
Incorrect Questions...
Question 5
- Question: Consider the following method. Which of the following is printed as a result of executing the following statement? System.out.println(mystery ( 6 ) ) ;
- Correct Answer: [4, 7, 12, 19, 28, 39]
- Explanation: This is the correct answer becaause the method mystery contains a loop that starts k at 1 and iterates, incrementing k by 1 until k exceeds n, which is 6. In each iteration, the Integer value k * k + 3 is added to the ArrayList seq. In the first iteration, when k is 1, the value 4 is added to the seq, which now contains {4}. In the second iteration, when k is 2, the value 7 is added to seq, which now contains {4, 7}. In the third iteration, when k is 3, the value 12 is added to seq, which now contains {4, 7, 12}. In the fourth iteration, when k is 4, the value 19 is added to seq, which now contains {4, 7, 12, 19}. In the fifth iteration, when k is 5, the value 28 is added to seq, which now contains {4, 7, 12, 19, 28}. In the sixth and final iteration, when k is 6, the value 39 is added to seq, which now contains {4, 7, 12, 19, 28, 39}.
Question 21
- Question: Consider the following method, which is intended to return the element of a 2-dimensional array that is closest in value to a specified number, val. Which of the following could be used to replace / missing code / so that findClosest will work as intended?
- Correct Answer: Math.abs (num - val) < minDiff
- Explanation: This is the correct answer because the algorithm uses nested enhanced for loops to iterate across all the elements in mat. The variable num is assigned the value of each element. If the positive difference between num and val is less than minDiff, num is the element of mat that is closest to val so far.
Question 23
- Question: Consider the following instance variable and method. Assume that animals has been instantiated and initialized with the following contents. What will the contents of animals be as a result of calling manipulate?
- Correct Answer: ["bear", "zebra", "bass", "cat", "koala", "baboon"]
- Explanation: This is the correct answer because list is an interface, which an ArrayList implements. Please note that List is no longer tested as part of the AP CSA exam and ArrayList will be used instead. The manipulate method contains a for loop with a loop control variable k that starts at the right most index of animals, decrements by 1 each time, until k is equal to 0. In the first iteration, when k is 5, if the element of animals at 5 (“baboon”) starts with a “b”, which it does, then this value is removed from the list and inserted at index 1. The list would then be {“bear”, “baboon”, “zebra”, “bass”, “cat”, “koala”}. In the second iteration, when k is 4, the element of animals at 4 (“cat”) does not start with a “b” and no changes are made to the list. In the third iteration, when k is 3, the element of animals at 3 (“bass”) starts with a “b”. This value is removed from the list and inserted at index 3. Since it was already at index 3, the list would not change. In the fourth iteration, when k is 2, the element of animals at 2 (“zebra”) does not start with a “b” and no changes are made to the list. In the fifth iteration, when k is 1, the element of animals at 1 (“baboon”) starts with a “b”. It is removed from the list and inserted at index 5. The list would then be {“bear”, “zebra”, “bass”, “cat”, “koala”, “baboon”}. Finally, k decrements to 0 which is not greater than 0 so the loop terminates.
Question 28
- Question: Directions: Select the choice that best fits each statement. The following question(s) refer to the following method. Which of the following is true of method mystery?
- Correct Answer: n will always be greater than 2 at // Point B.
- Explanation: This is the correct answer because the while loop only iterates while n is greater than 2 and //Point B is in the body of the while loop prior to any change to the value of n. At this point, n will always be greater than 2.
Question 30
- Question: Consider the following method. What value is returned as a result of the call scramble("compiler", 3)?
- Correct Answer: "ilercom"
- Explanation: This is the correct answer because the two parameter substring method returns the substring beginning at the first parameter and ending at the second parameter – 1. When word is assigned “compiler” and howFar is assigned 3, the value of word.substring(howFar + 1, word.length()) is “iler”. This is the substring of “compiler” beginning at 3 + 1 or 4 and ending at 8 – 1 or 7. The value of word.substring(0, howFar) is “com”. This is the substring of “compiler” beginning at 0 and ending at 2. The method returns “ilercom”.
Question 33
- Question: Consider the following code segment. What is printed as a result of executing the code segment?
- Correct Answer: Nothing is printed due to an infinite loop
- Explanation: This is the correct answer since k is never changed in the body of the while loop, it will always be 1 and less than 4. In a boolean expression with or (||) if one of the two expressions is true, the expression is true. This will cause an infinite loop. (Forgot that || is and)
General Reflections on Test
- Need to read questions more thoroughly and review Java syntax a bit more
- I got 6 wrong on the Test which would mean I scored 34/40...I can definitely do better especially since I had to search up a lot of the questions to get help on them
- I should definitely look over all the units and review them.
Links to Lessons
Week | Unit |
---|---|
1 | 2: OOP |
2 | 3: Boolean and IF |
2 | 4: Iteration |
2 | 5: Writing Classes |
3 | 6: Arrays |