# data[].attributes.body
Question 17: An algorithm for finding the average of N numbers is
average = sum/N
where N and sum are both integers

# data[].attributes.body
Often the most efficient computer algorithms use a divide-and conquer approach, for example, one in which a list repeatedly split into two pieces until a desired outcome is reached. Which of the following use a divide-and

# data[].attributes.body
19
Consider getCount below:

public static int getCount (String s, String sub)
{
int count = 0;
int pos = s.indexOf(sub);
while (pos >= 0)
{
s = s.substring(pos);
count++;

# data[].attributes.body
An Insect Class is to be written, containing the following data fields:
nextAvaiableID, which will be initialized to 0 outside the constructor and incremented each timer an insect is constructed.
idNum, which is initialized to the current value of nextAvaiableID when an Insect is constructed.
position, which will be initialized to the location in a garden where insect is facing when placed in the garden.
Which variable in the Insect class should be static?
A. age
b. nextAvaiableID
c idNum
d. position
e. direction
The correct answer is D. The position is not dynamic for it stays constant throughout the program.
Objective: public classes, private instance variables,public or private methods or constants

# data[].attributes.body
Often the most efficient computer algorithms use a divide-and-conquer approach, for example, one in which a list is repeatedly split into two pieces until a desired outcome is reached. Which of the following use a divide and conquer approach.
I Merge sort
II Insertion Sort
III Binary search
A. I only
B II only
C. III Only
D. I and III only
E. I, II, and III
D because insertion sort just builds one array item at one at a time.

# data[].attributes.body
If a, b, and c are integers, which of the following conditions is sufficient to guarantee that the expression

a < c || a < b && !(a == c)

evaluates to true?
(A) a < c
(B) a < b
(C) a > b
(D) a == b
(E) a == c

A
a < c is guaranteed to make the expression true, any of the other answer choices will give untrue answers

# data[].attributes.body
Refer to the following method.
public static int mystery(int n)
{
if (n == 1)
return 3;
else
return 3 * mystery(n - 1);
}

What value does Mystery(4) return?
A) 3
B) 9
C) 12
D) 27
E) 81

Answer: E
4 -1 = 3
3 * mystery (3)
3-1 = 2
3 * 3 * mystery (2)
2-1 = 1
3 * 3 * 3 * mystery(1)
3 * 3 * 3 * 3 = 81
-------------------------------------------------------------------------------------

# data[].attributes.body
Consider the following hierarchy of classes:
Parakeet -> Parrot -> Bird
Owl -> Bird

Assuming that each class has a valid default constructor, which of the following declarations in a client program are correct?

I. Bird b1 = new Parrot();
Bird b2 = new Parakeet();
Bird b3 = new Owl();

II. Parakeet p = new Parrot():
Owl o = new Bird();

III. Parakeet p = new Bird();

A) I only
B) II only
C) III only
D) II and III only
E) I,II, and III

Objective: "Understand inheritance hierarchies. Design and implement subclasses. Modify subclass implementations and implementations of interfaces."

Answer: A
Explanation:
I. Is correct because a parrot can be a bird, a parakeet can be a bird, and a owl can be a bird.

II. Is incorrect because a Parakeet cant be a parrot, and a bird is not always a owl.

III. Is incorrect as a bird is not always a parakeet.

Therefore only I is correct, which means A is the correct answer.

# data[].attributes.body
Question 6:
Objective: Return Statements
Refer to the following method.
public static int mystery(int n)
{
if (n == 1)
return 3;
else
return 3 * mystery(n - 1);
}
What value does Mystery(4) return?
(A) 3
(B) 9
(C) 12
(D) 27
(E) 81
Answer: (E) because, first you will plug in 4 into n.
4-1 = 3. So you will multiply 3*3 =9. Then you for n, you will plug in all the number from 4-1 including 1. This will ultimately give you 3^4 = 81.

# data[].attributes.headline
Lauren Whiteley          Question 22                       If a, b, and c are integers, which of the following conditions is sufficient to guarantee that the expressiona < c || a < b && !(a == c)evaluates to true?(A) a < c(B) a < b(C) a > b(D) a == b(E) a == c

# data[].attributes.subject
Lauren Whiteley          Question 22                       If a, b, and c are integers, which of the following conditions is sufficient to guarantee that the expressiona < c || a < b && !(a == c)evaluates to true?(A) a < c(B) a < b(C) a > b(D) a == b(E) a == c

# data[].attributes.body
answer A
Objective:&&, ||, ! and short-circuit evaluation
explanation: If a is less than c than it therefore cannot be equal to c which always makes the statement true.

# data[].attributes.body
public static int mystery(int n)
{
if (n == 1)
return 3;
else
return 3 * mystery(n-1);
}
What value does mystery(4) return?
A. 3
B. 9
C. 12
D. 27
E. 81
The correct answer is 81
The mystery function takes a power and applies it to three. 3 to the power of 4 is 81.
Objective 17, students must be able to understand the control structure of if/else statements.

# data[].attributes.body
A Large java program was tested, and no errors were found. What can be concluded?

Answers:
1. All of the preconditions in the program are correct.
2. The program may have bugs
3. The program has no bugs
4. Every method in the program may safely be used in other programs

Correct Answer: C

# data[].attributes.body
Question 9
An Insect Class is to be written, containing the following data fields:
nextAvaiableID, which will be initialized to 0 outside the constructor and incremented each timer an insect is constructed.
idNum, which is initialized to the current value of nextAvaiableID when an Insect is constructed.
position, which will be initialized to the location in a garden where insect is facing when placed in the garden.
Which variable in the Insect class should be static?
A. age
b. nextAvaiableID
c idNum
d. position
e. direction

Answer: D
D is the answer because position's value will stay constant throughout the entire stage of the program since it is only hooked to Insect class. If positon were to become a dynamic variable, as it is changed throughout the program, then the location and age variables would be ruined.

Objective: public classes, private instance variables,public or private methods or constants

# data[].attributes.body
Refer to the following method

Refer to the following method.
public static int mystery(int n)
{
if (n == 1)
return 3;
else
return 3 * mystery(n - 1);
}

What value does Mystery(4) return?
A) 3
B) 9
C) 12
D) 27
E) 81

answer E  3^4=81

# data[].attributes.body
If a,b, and c are integers, which of the following conditions is sufficient to guarantee that the expression

a < c II a < b && ! ( a == c)

A) a < c
B) a < b
C) a > b
D) a == b
E) a == c

The answer is A because a has to be less than c in order to make the statement always true . It will be true because of the fact that a will be equal to c

# data[].attributes.body
31
Refer to these declarations in a client program:
ThreeDigitInteger code = new ThreeDigitCode(127);
ThreeDigitInteger num  = new ThreeDigitInteger(456);

Which of the following will not cause an error?
I. if (code.isValid())
II. if (num.isValid())
III. if(((ThreeDigitCode)code).isValid())

A. I only
B. II only
C. III only
D. I and II only
E. I and III only

Answer: C, because the class ThreeDigitInteger does not have an isValid method. To avoid the error object used has to be ThreeDigitCode which the actual type.

# data[].attributes.body
Question 22: If a,b, and c are integers, which of the following conditions is sufficient to guarantee that the expression a < c I I a < b && !(a==c) is true?
Objective: &&, ||, ! and short-circuit evaluation
(A) a < c
(B) a < b
(C) a > b
(D) a == b
(E) a == c
Answer: (A) because if Value 1 is true, then the entire statement, is true. Thus, Value 1 will maintain to be true no matter what statements prove false.

# data[].attributes.body
Which of the following correctly creates a Customer object c?
1. Address a = new Address("125 Bismark St", "Pleasantville", "NY", 14850);
Customer c = new Customer("Jack Pratt", "747-1674", a, 7008);
2. Customer c = new Customer("Jack Pratt", "747-1674", "125 Bismark St, Pleasantville, NY 14850") , 7008);
3. Customer c = new Customer("Jack Pratt", "747-1674", new Address("125 Bismark St", "Pleasantville", "NY", 14850), 7008);

(A) 1 only
(B) 2 only
(C) 3 only
(D) 1 and 2 only
(E) 1 and 3 only

The objective of this question is to design classes. And the answer to this this question is E. The problem with B and D are with 2. 2 combines all the components of the address into one string when there are more productive ways to put the needed information into the object. It also does not use the Address constructor correctly. The reason E is correct over A and C is that it has both of their answers, and both of the answers are correct ways to create a Customer object. 3 is just a more succinct way of writing the code and takes up less space.

# data[].attributes.body
Question 17
An  algorithm for finding the average numbers is" "
If N is 0, when will the error be detected?
answer D
explanation: Only when the code is running will it register that N in that instance equals 0 and that is when it will catch the error.

# data[].attributes.body
Question 8
Often the most efficent computer algorithims use a divide-and-conquer approach, for example, one in which a list is repeadetely split into two pieces until a desiredoutcome is reached. Which of the following use a divide and conquer approach.
I Mergesort
II Insertion Sort
III Binary search
A. I only
B II only
C. III Only
D. I and III only
E. I, II, and III

Answer: D

D is the answer because both insertionsort and mergesort take pairs of variables and sort them into the best possible outcome in the most efficent amount of time. Binary Search does not sort numbers this way because it sorts using a pairing algorithim.The search algorithim, which is practical for the Binary Search algorithm to run.

# data[].attributes.body
22
If a, b, and c are integers, which of the following conditions is sufficient to guarantee that the expression

a < c || a < b && !(a == c)

evaluates to true?
(A) a < c
(B) a < b
(C) a > b
(D) a == b
(E) a == c

The correct answer is (A) because, since a < c in the expression is evaluated before any other expression because of the ||, if that expression is true, then the other side of the || will be true. For example: if value1 of the expression is true, the rest of the expression will be true; true || any. This ensures that the expression will evaluate to true.

# data[].attributes.body
22
If a,b, and c are integers, which of the following conditions is sufficient to guarantee that the expression a < c I I a < b && !(a==c) is true?
A. a < c
B. a < b
C. a > b
D. a == b
E. a == c

Answer:
A, because in the expression the values have to be true for the expression to be true. That is why a < c has to be the answer because it is given in the expression

# data[].attributes.body
A large Java program was tested extensively, and no errors were found.
Answer C

A) All of the preconditions in the program are correct
B) All of the post conditions in the program are correct
C) The program may have bugs
D) The program has no bugs
E) Every method in the program may safely be used in other programs

Even if the program has no errors it still may not accomplish what the programmer intends it to do.

# data[].attributes.body
A large Java program was tested extensively, and no errors were found. What can be concluded?
A. All of the preconditions are correct.
B. All of the postconditions are correct
C. The program may have bugs
D. the program has no bugs
E. Every method in the program may safely  be used in other programs .

Answer: C
Even it there are no errors that doesn't mean it's correct. It could have a completely different function.

# data[].attributes.body
A Client method computePay will return a worker's pay based on the number of hours worked.
Precondition: Worker w has worked the given number of hours
@param w a Worker
@param hours the number of hours worked
@return amount of pay for Worker w
public static double computePay(Worker w, double hours)
/*code*/
Which replacement for /*code*/ is correct?
A. return hourlyWage * hours;
B. return getHourlyWage() * hours;
C. return w.getHourlyWage() * hours;
D. return w.hourlyWage * hours;
E. return w.getHourlyWage() * w.hours;
The correct answer is C
Because the method is client side you would not be able to acces the private variables. B is wrong because the getHourlyWage is part of the worker class and E is also wrong because hours is not part of the workers class. C is correct.
This is shown in objective 20, That students must be able to know how to construct objects and call upon their methods and how to differentiate them from variables.

# data[].attributes.body
Refer to the following declarations:
String [] color = {"red", "green", "black"};
List<String> colorlist = new ArrayList<String>();

Which of the following correctly assigns the elements of the color array to colorlist? The final ordering of color in colorlist should be the same as in the colorarray.

I for (String col : colors)
colorList.add(col);

II for (String col : colorList)
colors.add(col);

III for (int i = color.length - 1; i >= 0; i--)
colorList.add(i, colors[i]);

Answers:
1. I only
2. II only
3. III only
4. II and II only
5. I, II, and III

Correct Answer: A

# data[].attributes.body
Refer to the following method.
public static int mystery(int n)
{
if (n == 1)
return 3;
else
return 3 * mystery(n - 1);
}

What value does Mystery(4) return?
A) 3
B) 9
C) 12
D) 27
E) 81

Correct Answer: E
Objective: Static class variables
Explanation:
When you pass 4 into mystery() it skips over the if part of the statement and instead goes into the Else part. In there you keep passing the variable into mystery(n-1) until it reaches 0, therefore you get
3 * mystery(3) = 9
3 * 3 * mystery(2) = 27
3 * 3 * 3 * mystery(1) = 81

# data[].attributes.body
1.
A large Java program was tested extensively and no errors were found. What can be concluded?

A. All of the preconditions are correct.
B. All of the postconditions are correct
C. The program may have bugs
D. Every method in the program may safely be used in other programs
E. Every method in the program may safely  be used in other programs
Answer:
C, because it is generally impossible to test all possible sets of code

# data[].attributes.body
Question 6: Refer to the following method.

public static int mystery(int n)
{
if (n ==1)
return 3;
else
return 3 * mystery(n-1);
}

What vale does mystery(4) return?
A. 3
B. 9
C.12
D. 27
E. 81

Correct Answer : E
Explanation: When 4 is passed in as the parameter for int mystery, it goes to the else part of the method because 4 is not equal to 1. The else part of the method changes the value of the int to (n-1). This turns the value into 3, and this continues to happen 3 more times to make n = 0. Once this happens the end output is 81.

# data[].attributes.body
A large Java program was tested extensively, and no errors were found.
Answer C

A) All of the preconditions in the program are correct
B) All of the post conditions in the program are correct
C) The program may have bugs
D) The program has no bugs
E) Every method in the program may safely be used in other programs

testing the knowledge of the student's understanding of basic java. The answer is C because any program regardless may have bugs because of all the possibilities of bugs there are in the world of java. Basically we have to understand the concepts of abstract classes and interfaces.

# data[].attributes.body
Question 1: A large Java program was tested extensively, and no errors were found. What can be concluded?
Objective: Basic Knowledge
(A) All of the preconditions are correct
(B) All the preconditions are correct
(C) The program may have bugs
(D) The program has no bugs
(E) Every method in the program may safely be used in other programs
Answer: (C) - because while a program might come up negative for bugs, doesn't mean that it is negative for all bugs, it might just negative for what that program was testing.

# data[].attributes.body
Question 1: A large java program was tested extensively, and no errors were found. What can be concluded?
A. All of the preconditions are correct.
B. All of the postconditions are correct
c. The program may have bugs
d. the program has no bugs
e. Every method in the program may safely  be used in other programs
Answer: C
The program may have bugs. This is because the program may run, but we do not know if there are any bugs in the code. If the program runs, it may be written correctly, but there could be bugs.