AP Exam Answers

¡Supera tus tareas y exámenes ahora con Quizwiz!

In terms of n, which Java expression represents the maximum number of times that /* perform some action */ could be executed?

(n+1)/2

hexadecimal number....

255

Which of the following best describes the contents of numbers after the following statement has been executed? int m = mystery(n);

All values in position m+1 through numbers.length-1 are greater than or equal to n.

which of the following will execute without throwing an exception?

II and III only

Consider the implementation of a writeDeck method that is added to the Deck class. /** Write the cards in the deck, one per line */ public void writeDeck() { /* implementation code */ } Which of the following is correct /* implementation code */? I System.out.println(deck); II for (Card card : deck) System.out.println(card); III for (Card card : deck) System.out.println((String) card);

II only

Which of the following are possible combinations for the value of lim, the number of times Statement S is executed, and the number of times Statement T is executed? I, II, III

II only

The following two implementations of /* missing code */ are proposed so that partialSum will work as intended Which of the following statements are true?

Implementation 1 does not work as intended, because it will cause an ArrayIndexOutofBoundsException.

When the programmer tests the constructor of the Caller class, she gets a NullPointerException. Which could be the cause of the error?

In the getList method, an attempt was made to add an Integer to an Arraylist that had not been created with new.

Which of the following changes should be made so that method findLongest will work as intended?

Insert the statement lenCount = 0; between lines 12 and 13

Refer to the doSomething method: // postcondition public static void doSomething(List<SomeType> list, int i, int j) { SomeType temp = list.get(i); list.set(i, list.get(j)); list.set(j, temp); } Which best describes the postcondition for doSomething?

Interchanges in list the objects indexed at i and j.

The method findLongest does not work as intended. Which of the following best describes the value returned by a call to findLongest?

It is the number of occurrences of the value target in nums

Which of the following best describes the problem with the given implementation of the shuffle method?

The last element of the returned array (result...) may not have the correct value

The boolean expression a[i] == max || !(max != [a]) can be simplified to:

a[i] == max

1 1 1 1 1 2 2 2 2 3 3 3 ... Which of the following code segments will produce this output?

for(int j = 1...) for(int k = 5; k >= j...) System.out.print(j + ..)

Which of the following can be used to replace /* missing code */ so that advance will correctly update the time?

hours = hours + minutes / 60; minutes = minutes % 60;

Assuming that k is a nonnegative integer and m = 2^k, what value is returned as a result of the call mystery(m)?

k

Given that n and k are integers and that the rewritten code performs the same task as the original code, which of the following could be used as a (condition) and (assignment statement)

n == 1 || n == 4 and k += n

What output will be produced by invoking secondTestMethod for a Tester Object, assuming that testArray contains 3,4,5?

3, 4, 5

Consider the following code segment. for(int k = 0; k < 20; k = k + 2) { if (k % 3 == 1) { .. .... What is printed as a result of executing the code segment?

4 10 16

Which of the following is printed as a result of the call mystery(1234)?

43211234

Which of the following changes to the sort method would correctly sort the integers in elements into descending order?

I and III

Which of the following code segments will assign the correct string to grade for a given integer score?

I and III only

Which of these constructors would be legal for the NamedPoint class?

I and III only

Which of the following method headings of isLargerThan can be added to the declaration of the Circle class so that it will satisfy the Shape interface? I, II, III

I only

Assume that sum1D works correctly. Which of the following can replace /* missing code */ so that the sum2D method works correctly?

I, II, and III

Which represents correct /* implementation code */ for the Rectangle constructor? I super(theLabels); II super(theLabels, theTopLeft, theBotRight); III super(theLabels); topLeft = theTopLeft; botRight = theBotRight;

III only

The color of a pixel can be represented using the RGB (Red, Green, Blue) color model, which stores values for red, green and blue, each ranging from 0 to 255. Ho many bits (binary digits would be needed to represent a color in the RGB model?

Not 8, 32

what is the effect of executing this method?

Not A ClassCastException will be thrown not A compile-time error will occur stating that there is no getLabels method in class Rectangle, Parallelogram or Square

Which statement about the quadrilateral class is false? public abstract class Quadrilateral { .... }

Not If the Quadrilateral class is used in a program, it must be used as a super class for at least one other class.

Which is true about the getNewTile algorithm?

Not The algorithm selects a random Tile from all tiles in the list.

Implementation 1 for(int j = 1; j < arr.length; j++) { prod[j] = prod[j - 1] + arr[k]; } Implementation 2 for(int j = 0; j ....) { for(int k = 0; k <= j....) { prod[j] = prod[j] * arr[k]; } Which of the following statements are true?

Not implementation 2 doesnt work as intended because the elements of prod are incorrectly assigned. not Both implementations work as intended but Implementation 1 is faster than implementation 2

which best describes what the mystery method does?

Not it converts the elements for arr to base - 10 not it sums the elements of arr

When will method whatIsIt cause a stack overflow (i.e., cause computer memory to be exhausted?) public static int whatIsIt(int x, int y) { if (x > y) return x * y ; else return whatIsIt (x - 1, y); }

Only when x <= y

Which of the following is the best postcondition for checkArray?

Returns the index of the largest value in array array

When the method was tested with known Pythagorean Triple, is PythTriple sometimes erroneously returned false? What was the most likely cause of error?

Round off error was caused by...

What is returned by the call mystery(0, arr.length - 1, num)?

The number of elements in arr that are less than num

A car dealership needs a program to store.... Which of the following is the best object-oriented program design?

Use one class, Car, with three instance variable...

animals.add("dog"); animals.add("cat"); .... .... ... What is printed as a result of executing the code segment?

[dog, fish, cat]

When the call test() is executed what are the values of a and n at the point indicated by /* End of method */?

a -world n - 6

Which assertion is true just before each execution of the while loop?

arr[first] <= key <= arr[last] or key is not in arr

The programmer's plan to write the Book class first is an example of

bottom-up development

which matrix will be the result of a call to changeMatrix(mat)?

not 1 2 6 2 4 5

Which best describes what method findSomething does? Method findSomething returns true only if

not Arrays a and b contain identical elements in the same order not array a contains at least one element that is also in b not Arrays and b are permutations of each other

Which replacements for /* some value */ will always result in correct execution of the findMin method?

not I and III not III only not I only

ClassOne c1 = new ClassOne(); ClassOne c2 = new ClassTwo(); Which of the following will cause an error? I, II, III

not I only

I. int[] bingo Card.... II. boolean[] bingoCard.... III. ArrayList...

not III only

A large list of numbers is to be sorted in ascending order. Assuming that a "data movement" is a swap or reassignment of an element, which of the following is a true statement?

not The number of data movements in insertion sort is independent of the initial arrangement of elements

What will values contain as a result of executing mystery(values)?

not [4, 2, 5, 3] not [0, 0, 4, 2, 5, 0, 3, 0]

Which of the following is a correct replacement for /* more code */?

not first = str1.substring(o, pos -1); last = str1.substring(pos) not first = str1.substring(0, pos); last = str1.substring(pos + 1, str1.length();

What is printed as a result of the call pigeon.act()?

not fly chirp

The relationship between the PLayerGroup and Player classes is an example of

not inheritance not an interface

Which represents correct /* code to add integer to list */?

not list.add( (int) (Math.random() * 101));

Which method described above corresponds to someMethod?

not mirrorDiagonalRightToLeft not mirrorHorizontalBottomToTop

What is printed as a result of the call fido.act()?

run eat bark sleep

Using the information above: Which of the following represents /* implementation */ code for the constructor in the Card class?

suit = cardSuit;

Which /* code to swap tile at position size with tile at position index */ performs the swap correctly?

tiles.set(index, tiles.get(size)); tiles.set(size, temp);

Which of the following can be used to replace /* missing expression */ so that the code segment will work as intended? public class TimeRecord { .... ... }

total.advance(timeCards[k].getHour(), time Cards[k].getMinutes())


Conjuntos de estudio relacionados

Chapter 19 Anatomy and Physiology

View Set

Chapter 13: Employees Rights and Discipline

View Set

Paleolithic Age VS Neolithic Age

View Set

My Midterm Questions - CIST1220 - Structured Query Language-SQL

View Set

1. Introducción a la Fisiología Celular y Biofísica

View Set

Chapter 8: Miscellaneous Personal Lines Coverage

View Set