IMPORTANT:  Due to the lateness of this study guide being posted, the quiz will be given on Tuesday April 20 in the lab. 

Topics you are responsible for on Cumulative Quiz 1 (Chapters 1 - 5)

Some sample questions from the quiz.  Half of these will appear on the quiz verbatim (though I may switch the order of the answers).  In addition at least one free response question will be taken from the worksheets that were due on Friday.

  1. When you have a series of && or || operations stop evaluation early once the result is certain. (eg: false && anything will stop evaluating before it sees the other parts of the expression) A) compound boolean expression B) assertion C) short-circuit evaluation D) decrementation E) none of the above

  2. A variable or method in a class visible only to that class. A) public B) final C) assertion D) private E) none of the above

  3. The form of recursion where the answer is built up in the return statement. (eg: return 1 + myfunc(a – 1); A) base case B) assertion C) embedded recursion D) tail recursion E) none of the above

  4. The form of recursion where the answer is built up in an extra argument to the recursive function A) embedded recursion B) tail recursion C) base case D) assertion E) none of the above

  5. The numeric value of  17 % 5 is A) 3 B) 0 C) 12 D) 2 E) none of the above

  6. The numeric value of  17 / 5 is A) 3 B) 0 C) 12 D) 2 E) none of the above

  7. The numeric value of  (-17) % 5 is A) -3 B) 0 C) -2 D) 12 E) none of the above

  8. Which of the following is true for this coding?

int x = 5;

if (x = 3) z  = x;    

else z = 2;

A) the coding assigns 5 to z B) the coding assigns 3 to z C)the coding assigns 2 to z D) there will be a compiler error E) none of the above is true

  1. Choose the correct missing code for the blank to print exactly 3 numbers on every line.

for (int k = 5;  k < 65;  k++)

            if ( ________________ == 1) System.out.println ("  " + k);

            else  System.out.print ("   " + k);

A) k B) k / 3 C) k = 3 D) k % 3 E) none of the above

  1. if (x == 5 || y > 2) is fully equivalent to if (! ( _______________ )) where the blank is filled by A) x != 5 && y <= 2 B) x == 5 & y > 2 C) x == 5 || y < 2 D) !(x == 5) || !(y == 2) E) none of the above

  2. Choose the correct option to fill in the blank suich that it will assign x to the smaller value between y and z: if (y < z) ______________;

    A) x = 0; else z = x; B) y = x; else z = x; C) x = y; else x = z; D) y = z; x = z; E) none of the above

  3. Assume that read() is a method that obtains a single number that the user enters, and that the user chooses to enter the numbers 3  2  1  0  -1  -2  -3 in that order.  What number does this coding print?

double sum = 0;

for (double x = read();  x != 0;  x = read())    

            sum += x;

System.out.println (sum);

A) 6 B) 5 C) 3 D) 0 E) none of the above

13) What is the value of x printed by this coding?

int x = 6;

do  {

            x += 3;

}while (x % 2 == 1);

System.out.println (x);

A) 3 B) 6 C) 9 D) 12 E) none of the above

  1. Assume that read() is a method that obtains a number that the user enters.  Choose the option that fills the blank such that the code prints the number of the input values that are larger than 20.

int n = 0;

for (int x = read();  x != 0;  x = read())    

            if ( ________________ )

                        n++;

System.out.println (n);

A) x > 20 B) x < 20 C) x == 20 D) x.compareTo(20) > 0 E) none of the above

  1. The Child class has the heading "class Child extends Parent".  Choose the option that fills in the blank so that calling the Child constructor begins by calling the constructor in the Parent class that also has the same double parameter.

public Child (double data)     {     _______________ (data) ;     spot = 17;     }

  A) this B) constructor C) super.constructor D) super E) none of the above

  1. The Child class has the heading "class Child extends Parent".  A method named stuff is in the Child class. Which of the following variables in Parent can the coding within stuff refer to? A) a private variable declared outside of all methods B) a public variable declared outside of all methods C) a parameter of some other method D) B & C E) none of the above

  2. When can two methods in the same class have exactly the same name? A) when they have a different number of parameters B) when the values they return have different types C) when they each have one parameter but those parameters have different types D) when one is public and the other is private E) A & C

  1. The BankAccount class has an instance variable named balance.  A method in another class has the two statements BankAccount mine; mine.set();  Which of the following statements could be written inside that set method to assign 12 to mine's balance? A) int balance = 12; B) balance = 12; C) this.balance = 12; D) A & C E) B & C

  2. Which of the following segments of code outputs 0? A) System.out.println(“Hello”.length-5); B) System.out.println(“Hello”.size()-5); C) System.out.println(“Hello”.length()-”5”); D) System.out.println(“Hello”-”Hello”); E) none of the above

  1. Which of the following descriptions properly define a static method? A) a method that will always return the same answer B) a method that requires an instance of a class to work C) a method that returns a value D) a method that does not require an instance of a class in order to operate E) none of the above

  2. Assuming you have a properly defined Random object called fred, which of the following code segments will return a Random value between 10 and 20? A) fred.nextInt(10, 20); B) fred.nextInt(20)-10; C) fred.nextInt(11)+10; D) fred.nextInt(200); E) none of the above