Score: 24/40

The Good

  • I did good with the minor mathematic problems and basic logic problems.
    • I have experience with logic questions since I’ve done problems on that, so I don’t have too much trouble.
  • Problems which had less variables were easier since keeping track of data is easier

The Bad

  • I messed up on many complex problems
    • Most complex problems require you to track lots of data
    • I am very bad at keeping track of things in my head, so it was difficult for me to manipulate data
    • I think that using a piece of paper or a Google Doc would help keep track of stuff
  • I messed up on complex technical problems
    • Some problems require an intricate understanding of Java
      • For example: the result of integer division or the properties of classes or inheritance
      • Complex problems with OOP were difficult, so I should study that more.
  • I struggle on difficult

Q4

image

What is printed as a result of executing the code segment?

  1. Value is: 21
  2. Value is: 2.3333333
    1. I originally chose this. However, I didn’t realize that the numbers were ints and that integer division rounds off the numbers. This answer is correct if the numbers are doubles which they are not. I should make sure to examine every detail of the code next time. The answer is C.
  3. Value is: 2
  4. Value is: 0
  5. Value is: 1

Q6

Consider the following method that is intended to determine if the double values d1 and d2 are close enough to be considered equal. For example, given a tolerance of 0.001, the values 54.32271 and 54.32294 would be considered equal.

image

Which of the following should replace / * missing code * / so that almostEqual will work as intended?

  1. return (d1 - d2) <= tolerance;
    1. I chose this, but I forgot that you need to use the absolute value. If d1 >= d2, the code works fine. Otherwise, you will get a wrong return value if the number result is negative. I need to make sure that I pay attention to the math. The answer is E.
  2. return ((d1 + d2) / 2) <= tolerance;
  3. return (d1 - d2) >= tolerance;
  4. return ( (d1 + d2) / 2) >= tolerance;
  5. return Math.abs(d1 - d2) <= tolerance;

Q9

Consider the following method that is intended to return the sum of the elements in the array key.

image

Which of the following statements should be used to replace / * missing code * / so that sumArray

  1. sum = key [ i ] ;
  2. sum += key [i - 1] ;
  3. sum += key [ i ] ;
    1. I hadn’t considered the possibility of reaching an ArrayIndexOutOfBoundsException because i is too high. The correct answer is B because it prevents the out of bounds exception and makes sure the sum is correct.
  4. sum += sum + key[i - 1] ;
  5. sum += sum + key [ i ] ;

Q15

Consider the following method, isSorted, which is intended to return true if an array of integers is sorted in nondecreasing order and to return false otherwise.

image

Which of the following can be used to replace /* missing code */ so that isSorted will work as intended?

image

  1. I only
  2. II only
    1. The answer is A. I made the same mistake again of not considering the out of bounds exception and making sure I don’t access data improperly. I should work on writing the values down because I find it hard to run the code in my head.
  3. III only
  4. I and II only
  5. I and III only

Q16

Consider the following incomplete method that is intended to return an array that contains the contents of its first array parameter followed by the contents of its second array parameter.

image

Which of the following expressions can be used to replace /* index */ so that append will work as intended?

  1. j
  2. k
    1. The correct answer is D. I went by this problem too fast. I looked at the other code with j and rushed through it and messed up. I should make sure to pay attention more to the answer choices and not blindly select something.
  3. k + a1.length - 1
  4. k + a1.length
  5. k + a1.length + 1

Q17

Consider the following code segment.

image

Which of the following represents the contents of arr as a result of executing the code segment?

  1. {1, 2, 3, 4, 5, 6, 7}
  2. {1, 2, 3, 5, 6, 7}
    1. The correct answer is C. I think I chose this answer because I saw the initial numbers in the correct order, but I didn’t think there would be another 7 at the end. Once again, using paper and pencil would help me keep track of the data.
  3. {1, 2, 3, 5, 6, 7, 7}
  4. {1, 2, 3, 5, 6, 7, 8}
  5. {2, 3, 4, 5, 6, 7, 7}

Q21

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.

image

Which of the following could be used to replace / * missing code * / so that findClosest will work as intended?

  1. val - row [num] < minDiff
  2. Math.abs (num - minDiff) < minDiff
  3. val - num < 0.0
  4. Math.abs (num - val) < minDiff
  5. Math.abs (row [num] - val) < minDiff
    1. The correct answer is D. I was actually going to select D, but I changed my mind later and I’m not too sure why. The loop is an enhanced for loop, so accessing num directly would have worked like how you can do in Python. For some reason, I changed my answer to E since that’s how it works in C.

Q22

Consider the following Book and AudioBook classes.

image

Consider the following code segment that appears in a class other than Book or AudioBook.

image

  1. Line 2 will not compile because variables of type Book may not refer to variables of type AudioBook.
  2. Line 4 will not compile because variables of type Book may only call methods in the Book class.
  3. Line 5 will not compile because the AudioBook class does not have a method named toString declared or implemented.
    1. I did not realize the inheritance of the classes, which means that there would be a toString method even though it’s not explicitly in the AudioBook class. The correct answer is B.
  4. Line 6 will not compile because the statement is ambiguous. The compiler cannot determine which length method should be called.
  5. Line 7 will not compile because the element at index 1 in the array named books may not have been initialized.

Q23

Consider the following instance variable and method.

image

Assume that animals have been instantiated and initialized with the following contents.

image

What will the contents of animals be as a result of calling manipulate?

  1. [“baboon”, “zebra”, “bass”, “cat”, “bear”, “koala”]
  2. [“bear”, “zebra”, “bass”, “cat”, “koala”, “baboon”]
  3. [“baboon”, “bear”, “zebra”, “bass”, “cat”, “koala”]
    1. The correct answer is B. I messed up running the code in my head and probably should have used a piece of paper or a document to keep track of the data and where it is going.
  4. [“bear”, “baboon”, “zebra”, “bass”, “cat”, “koala”]
  5. [“zebra”, “cat”, “koala”, “baboon”, “bass”, “bear”]

Q25

A rectangular box fits inside another rectangular box if and only if the height, width, and depth of the smaller box are each less than the corresponding values of the larger box. Consider the following three interface declarations that are intended to represent information necessary for rectangular boxes.

image

Which of the interfaces, if correctly implemented by a Box class, would be sufficient functionality for a user of the Box class to determine if one Box can fit inside another?

  1. I only
  2. II only
    1. The correct answer is D. I knew that II was correct but didn’t fully consider I. I hadn’t thought about the idea of getting the original dimensions to perform the comparison and only thought about using the smaller dimensions instead.
  3. III only
  4. I and II only
  5. I, II, and III

Q26

Assume that the array arr has been defined and initialized as follows.

image

Which of the following will correctly print all of the odd integers contained in arr but none of the even integers contained in arr ?

image

I didn’t realize that the code prints out the indices of the odd elements rather than their actual values. The only answer which loops through the array correctly and displays the elements is A.

Q28

image

Which of the following is true of method mystery ?

  1. x will sometimes be 1 at // Point B.
  2. x will never be 1 at // Point C.
    1. The correct answer is E because n has to be greater than 2 in order to enter the loop and arrive at Point B. I forgot that you could call the function with a number less than 2 (like 1) and then end up returning 1 at point C.
  3. n will never be greater than 2 at // Point A.
  4. n will sometimes be greater than 2 at // Point C.
  5. n will always be greater than 2 at // Point B.

Q29

image

Which of the following code segments will produce the same output as the code segment above?

image

The correct answer is E. B prints the correct number of values, but I didn’t realize that it prints the wrong values itself. E is correct because it both prints the right number of values and also prints the correct values.

Q31

image

image

What is printed as a result of executing the code segment?

  1. 5 2 1 3 8
  2. 5 7 3 4 11
    1. To be honest, I just guessed on this one. I think I flagged it, but accidentally unflagged it somehow and just never came back to this one. However, the correct answer is C.
  3. 5 7 8 11 19
  4. 7 3 4 11 8
  5. Nothing is printed because an ArrayIndexOutOfBoundsException is thrown during the execution of method mystery.

Q34

image

Which of the following replacements for /* missing code */ will correctly implement the Circle constructor?

image

  1. I only
  2. II only
  3. III only
  4. II and III only
    1. I knew that II was correct but it turns out that III was wrong. III causes a compile time error since it’s trying to access variables improperly. Only II is correct, so the right answer is B.
  5. I, II, and III

Q40

image

What is printed as a result of the call whatsItDo (“WATCH”) ?

    1. WATC
    2. WAT
    3. WA
    4. W
  1. B
    1. WATCH
    2. WATC
    3. WAT
    4. WA
  2. C
    1. W
    2. WA
    3. WAT
    4. WATC
  3. D
    1. W
    2. WA
    3. WAT
    4. WATC
    5. WATCH
  4. E
    1. WATCH
    2. WATC
    3. WAT
    4. WA
    5. W
    6. WA
    7. WAT
    8. WATC
    9. WATCH

I selected A, but the correct answer is C. I didn’t realize it prints the content backwards, so I selected the inverse answer. I think I should use paper for this one too to store the variables and see which values are in the temporary variable.