REFLECTION, Test Corrections - FINAL
Reflection of MCQ: I did not get great score. I think this is because of poor planning and studying methods, and I didn't take the final until late at night, which hindered my ability to get a great score. I also think that I didn't study enough and did not put enough time into getting the content. I think will do test corrections moving forward to ensure a better score and I hope to do better than my first attempt. My most missed type of question were ones with arrays, where they gave me a segment of code and asked me to analyze it to answer a question. An example could me number 31, where the answer isn't the "nothing is printed because an ArrayIndexOutOfBoundsException is thrown during the execution of method mystery", but the answer is: Incorrect. Since the loop terminates when k is data.length – 1 no ArrayIndexOutOfBoundsException is thrown. The values of k that cause the loop to execute are 0, 1, 2 and 3. Since k + 1 is also used as an index in the loop body, indices 0, 1, 2, 3 and 4 are accessed, all of which are valid indices in data. I had difficulty deciphering what the code was saying, so more often than not, I required help from the internet. I think that I definitely need to study java syntax and semantics more before the next test.
I think I need more practice with arraylists for sure. I also think I had trouble with a lot of basic logical questions. For example, question 35, where it asked me what the program segment would print. I ignored the second iteration of the loop. The answer would be: Incorrect. This is the value of result after the first iteration of the loop. However, at this point num /= 10 results in num being updated to the value of itself divided by 10 using integer division. The variable num is assigned the value 257, which is greater than 0 and the loop continues.
Test Corrections:
Q4:
Correction: 2 is Correct. When we evaluate the express(x < 10) && (y < 0) for x having the value 7 and y having the value 3, x < 10 evaluates to true, since 7 is less than 10, and y < 0 evaluates to false, since 3 is not less than 0. The logic operator && evaluates to true when both conditions are true and evaluates to false otherwise. Since the second condition is false, the boolean expression is false. As a result, the compiler will skip the first output statement and execute the statement in the else. The expression x / y is integer division for 7 / 3, which is 2.
Q5:
Correction: C is Correct. 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}.
Q6:
Correction: is Correct. To determine the positive distance between two values, we need to take the absolute value of the difference using Math.abs. Once the difference is calculated, the method should return true if this difference is less than or equal to the tolerance and false otherwise.
Q8:
Correction: C is Correct. Choice I uses the no parameter constructor to create a new Student object and assign it to variable a of type Student. Choice II uses the two-parameter constructor, with the parameters in the order of String then int, to create a new Student object and assign it to variable b of type Student. Choice III attempts to use the two-parameter constructor, however the order of the parameters is a String followed by a String. There is no two-parameter constructor with two String parameters. This statement will cause a compile time error.
Q9:
Corrections: B is correct. The elements of array key have indices 0 to key.length – 1. Since the for loop control variable i is initialized to 1 and will increase by 1 until it is equal to key.length, the access to key should be adjusted by 1, otherwise the value at index 0 will not be included in the sum and when i is key.length an ArrayIndexOutOfBoundsException will be thrown.
Q10:
Corrections: B is Correct. The for loop starts the loop control variable k with the value 0 and increments by 1 until k == arr.length - 1. In each iteration of the for loop, the element of arr at index k is compared with the element of arr at index k + 1. If the current value is greater than the next value, the current value of k followed by the element at index k is printed. Since the comparison is using the current value of k as an index as well as the subsequent value of k, the for loop must not iterate when k is the last index of arr (arr.length – 1). In the first iteration, k has the value 0, arr[0] is 7 which is greater than arr[1] which is 2, therefore 0 7 is printed. In the second iteration, k has the value 1, arr[1] is 2 which is not greater than arr[2] which is 5. Nothing is printed. In the third iteration, k has the value 2, arr[2] is 5 which is greater than arr[3] which is 3, therefore 2 5 is printed. In the fourth iteration, k has the value 3, arr[3] is 3 which is greater than arr[4] which is 0, therefore 3 3 is printed. In the fifth iteration k has the value 4, arr[4] is 0 which is not greater than arr[5] which is 10. Nothing is printed. The value of k is incremented and has a value of 5, which is equal to arr.length – 1 and the loop terminates.
Q11:
Corrections: C is Correct. Correct. The for loop control variable k starts with the value 3, is incremented by 1 and terminates the loop when its value is arr.length – 1. In the first iteration, when k is 3, arr[3] is assigned the value arr[4]. The contents of the arr have been updated to {1, 2, 3, 5, 5, 6, 7}. In the second iteration, when k is 4, arr[4] is assigned the value arr[5]. The contents of arr have been updated to {1, 2, 3, 5, 6, 6, 7}. In the third iteration, when k is 5, arr[5] is assigned the value arr[6]. The contents of arr have been updated to {1, 2, 3, 5, 6, 7, 7}. Then k is incremented to 6 and the loop terminates.
Q12:
Corrections: B is Correct. 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.
Q13:
Corrections: C is Correct. This algorithm uses an enhanced for loop to assign each element in arr to x. Using the modulus (%) operator to determine the remainder when dividing by 2, each value is checked to see if it is not even. If x is even, then x % 2 will be 0, since there is no remainder when you divide an even number by 2. If x is odd, then x % 2 will not equal 0, it will equal 1.
Q14:
Corrections: E is Correct. 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.
Q15:
Corrections: C is Correct. Passing a reference parameter results in the formal parameter and the actual parameter being aliases. They both refer to the same object. Any updates made to the referenced array when mystery is called are being made on the single array that is reference by both data and values. The for loop has a loop control variable k that starts at 0, increments by 1 for each iteration, and the loop terminates once k is data.length – 1. In each iteration of the loop, the element at index k + 1 is assigned the sum of the values at index k and k + 1. In the first iteration, data[1] is assigned 5 + 2 (data[[0] + data[1]) or 7. Changing the array referenced by both data and values to be {5, 7, 1, 3, 8}. In the second iteration, data[2] is assigned 8, changing the array to {5, 7, 8, 3, 8}. In the third iteration, data[3] is assigned 11, changing the array to {5, 7, 8, 11, 8}. In the fourth and final iteration, data[4] is assigned 19, changing the array to {5, 7, 8, 11, 19}. Since call by value is used when calling mystery and passing an array, the reference to the array values is passed, meaning data will be assigned this same reference. This establishes an aliasing relationship where both values and data are referencing the same array and no copy of the array is made. Any updates made when mystery is called are being made on the single array that is reference by both data and values.
Q16:
Corrections: E is Correct. The modulus operator (%) evaluates to the remainder when the first operand is divided by the second operand. For example, 2574 % 10 evaluates to 4 the remainder when 2574 is divided by 10. In the first iteration of the loop, result is assigned 0 10 + 2574 % 10 or 0 + 4 or 4. The value of num is updated to 257 since the division is integer division between two int values. In the second iteration, result is assigned 4 10 + 257 % 10 or 40 + 7 or 47 and num is assigned 25. In the third iteration, result is assigned 47 10 + 25 % 10 or 470 + 5 or 475 and num is assigned 2. In the fourth iteration, result is assigned 475 10 + 2 % 10 or 4750 + 2 or 4752 and num is assigned 0. At this point the loop will terminate and 4752 will be printed to the screen.
Q17:
Corrections: C is Correct. The first conditional tests to see if x is even, if it is, y will be assigned the value 3. The value 8 is an even number and will test this condition. If x is not even, then the second test will check if x is greater than 9. If x is an odd number greater than 9, then y will be assigned the value 5. The value 11 is an odd number greater than 9. If x is an odd number but not greater than 9, then y is assigned the value 1. The value 9 is an odd number that is not greater than 9.
Reflection of the Trimester: This trimester, I liked the work I did. I think I need to focus on making sure I"m more efficient in class and less distracted. I enjoyed working with sockets somewhat but I want to do more backend. I think it's difficult for me to venture into new things in fear that they will not work, and the adjustment of this trimester to school itself was pretty difficult. Next trimester, however, I will align my schedule accordingly.