Trimester 2 Final - College Board Practice
MCQs and FRQs I did for practice
2015 Practice Exam MCQ
On the MCQ, I earned a 33/39 overall (84.61%). Here is an analysis of the problems I got wrong.
Overall, my issue was that I rushed the test and didn’t know some of the intricacies of a few Java methods.
Question 15
Question
Consider the following method.
public static void showMe(int arg) {
if (arg < 10) {
showMe(arg + 1);
} else {
System.out.print(arg + " ");
}
}
What will be printed as a result of the call showMe(0)
?
Solving the Problem
If arg
is less than 10, the number will simply be incremented until the number is 10, then that number will be printed.
My Mistake: I rushed this problem, so I didn’t notice that it said <
and not <=
.
What do I need to do in future?
Spend more time on the questions to pay attention to small details.
Question 19
Question
For which of the following conditions will nothing be printed?
int x = 1;
while (/* condition */)
{
if (x%2==0)
{
System.out.print(x+" ");
}
x = x + 2
}
The following conditions have been proposed.
I: x < 0
II: x <= 1
III: x < 10
Solving the Problem
It’s immediately clear that I and II are correct, since the while loop will never even reach 2, the first even number. However, realizing III is correct requires actually trying the loop and realizing that only odd numbers will be iterated on so the print will never be called.
What do I need to do?
I have to actually go through the question and not just be lazy and quickly answer it.
Question 25
Question
What is printed as a result of executing the code segment?
int count = 0;
for (int x = 0; x < 4; x++) {
for (int y = x; y < 4; y++) {
count++;
}
}
System.out.println(count);
Solving the Problem
Basically, this counts like follows:
1) 0 0
2) 0 1
3) 0 2
4) 0 3
5) 1 1
6) 1 2
7) 1 3
8) 2 2
9) 2 3
10) 3 3
Therefore, the answer is 10.
What to do in future?
I didn’t notice that it started at y=x
, so I counted more pairs (16) and gave the wrong answer. I need to read the questions more carefully.
Question 30
Question
Solving the Problem
Trying out some sample testcases can give you an idea of which answer should be correct. It becomes clear that II is the correct solution.
What to do in future?
I didn’t notice that option I had if
repeated three times instead of an if-else if-else
, so I mistakenly thought it was correct. I need to look more slowly at the problem and how to solve it, and actually try some testcases.
Question 38
Question
Solving the Problem
Here, it’s important to just try and plug in some example numbers and just see what happens as a result. It becomes clear that we add one each time we encounter val
, so we’re counting the amount of time val
occurs.
What to do in future?
My mistake was that I didn’t actually try plugging in numbers, if I took my time and did that I would’ve understood this better. Also, I overthought the problem and thought it was only adjacent values since I didn’t plug in numbers to get a better idea.
Question 39
Question
Solving the Problem
If you understand that ArrayList.set()
returns the old value, the answer is clear.
What to do in future?
Better understand the methods of ArrayList
s and other important classes in java.
2014 FRQ
I graded myself based on comparing my logic to other’s solutions (like this one) and using AI.
Problem 1
Part A
Score: 8/9, made mistake with usage of .length()
method.
My solution:
private String recombine(String word1, String word2) {
return word1.substring(0, word1.length/2) + word2.substring(word2.length/2, word2.length);
}
Correct solution:
private String recombine(String word1, String word2) {
return word1.substring(0, word1.length()/2) + word2.substring(word2.length()/2, word2.length());
}
What did I do wrong? I was simply using strings like I would a list and using the .length
property. However, .length
on a string is actually a method, so I needed to call .length()
.
Part B
Score: 9/9
private String[] mixedWords(String[] words) {
for (int i = 0; i < words.length; i += 2) {
String word1 = words[i];
String word2 = words[i+1];
words[i] = recombine(word1, word2);
words[i+1] = recombine(word2, word1);
}
return words;
}
public class WordScrambler {
private String[] scrambledWords;
public WordScrambler(String[] wordArr) {
scrambledWords = mixedWords(wordArr);
}
// part (a)
private String recombine(String word1, String word2) {
return word1.substring(0, word1.length()/2) + word2.substring(word2.length()/2, word2.length());
}
private String[] mixedWords(String[] words) {
for (int i = 0; i < words.length; i += 2) {
String word1 = words[i];
String word2 = words[i+1];
words[i] = recombine(word1, word2);
words[i+1] = recombine(word2, word1);
}
return words;
}
public static void main(String[] args) {
String[] words = {"apple", "pear", "this", "cat"};
WordScrambler scrambler = new WordScrambler(words);
for (String word : scrambler.scrambledWords) {
System.out.println(word);
}
// recombine("apple", "pear"); // apar
// recombine("pear", "apple"); // peple
}
}
WordScrambler.main(new String[0]);
apar
peple
that
cis
Problem 2
Part A
Score: 9/9
public static int getPeakIndex(int[] array) {
if (array.length < 3) return -1;
for (int i = 1; i < array.length-1; i++) {
if (array[i-1] < array[i] && array[i+1] < array[i]) {
return i;
}
}
return -1;
}
Part B
Score: 9/9
public static boolean isMountain(int[] array) {
int peakIndex = getPeakIndex(array);
if (peakIndex == -1) {
return false;
}
return isDecreasing(Arrays.copyOfRange(0, peakIndex) && isIncreasing(Arrays.copyOfRange(peakIndex, array.length));
}
public class Mountain {
public static int getPeakIndex(int[] array) {
if (array.length < 3) return -1;
for (int i = 1; i < array.length-1; i++) {
if (array[i-1] < array[i] && array[i+1] < array[i]) {
return i;
}
}
return -1;
}
public static void main(String[] args) {
int[] array = {11, 22, 33, 55, 77};
System.out.println(getPeakIndex(array)); // 1
}
public static boolean isMountain(int[] array) {
int peakIndex = getPeakIndex(array);
if (peakIndex == -1) {
return false;
}
return isDecreasing(Arrays.copyOfRange(0, peakIndex) && isIncreasing(Arrays.copyOfRange(peakIndex, array.length));
}
}
Mountain.main(new String[0]);
-1
Problem 3
Part A
Score: 9/9
private double computeTemp(int row, int col) {
if (row == 0 || col == 0 || row == temps.length || col == temps[row].length) {
return temps[row][col];
}
return (temps[row-1][col] + temps[row+1][col] + temps[row][col-1] + temps[row][col+1])/4;
}
Part B
Score: 9/9
public boolean updateAllTemps(double tolerance) {
double[][] temps2;
for (int r = 0; r < temps.length; r++) {
for (int c = 0; c < temps[r].length; c++) {
temps2[r][c] = computeTemp(r, c);
}
}
for (int r = 0; r < temps.length; r++) {
for (int c = 0; c < temps[r].length; c++) {
if (Math.abs(temps2[r][c] - temps[r][c]) > tolerance) {
temps = temps2;
return false;
}
}
}
temps = temps2;
return true;
}
public class TemperatureGrid
{
private double[][] temps;
private double computeTemp(int row, int col) {
if (row == 0 || col == 0 || row == temps.length || col == temps[row].length) {
return temps[row][col];
}
return (temps[row-1][col] + temps[row+1][col] + temps[row][col-1] + temps[row][col+1])/4;
}
public boolean updateAllTemps(double tolerance) {
double[][] temps2;
for (int r = 0; r < temps.length; r++) {
for (int c = 0; c < temps[r].length; c++) {
temps2[r][c] = computeTemp(r, c);
}
}
for (int r = 0; r < temps.length; r++) {
for (int c = 0; c < temps[r].length; c++) {
if (Math.abs(temps2[r][c] - temps[r][c]) > tolerance) {
temps = temps2;
return false;
}
}
}
temps = temps2;
return true;
}
}