| CIT 590 Midterm Exam | Name ______________________________ |
Where I ask for a statement, give me a statement, not a complete method. Where I ask for a method, give me a method, not a class. And so forth.
foo to be of
type double with an initial value of 17.76.
students to be an array of
Student objects, but don't give it an initial value.
books to
be an ArrayList of Book objects. Use the correct
syntax for generics (that is, make sure your ArrayList will hold
Books and nothing else).
fiddle that takes no arguments and returns no value.
faddle that takes two
integer arguments and returns a String. Although this method does
nothing, it should be complete enough to compile without error.
count.
count.
true
from a method if x is greater than 5, and false otherwise.
index, but resets index to zero if adding 1 would
make it equal to length.
sum to the sum of all the values
in the one-dimensional array scores of integers.
switch statement to set the String variable
word to either "one", "two", or
"many", depending on whether the integer variable
count is 1, 2, or some other value,
respectively.
RuntimeException if the variable k is negative.Keep all answers brief and to the point. Do not include information that was not asked for--it may cost you points. You may be penalized for excesssively verbose answers.
private. Why?
double parameter is between 0.1 and 1.0. As the
first step of your method, you want to ensure that this parameter is
in the legal range. There are two ways to do this:public, instead of using an
assert statement, you should throw some kind
of Exception for illegal values of the parameter. Why?
private, instead of throwing an
Exception, you probably should assert
that the value of the parameter is in the legal range. Why?
Random rand = new Random();
do {
int row = rand.nextInt(10);
int col = rand.nextInt(10);
} while (row == col);
this cannot be used in a static method.
Why not?
implements an interface, what is
that class "promising" to do?
public String toString() {
top = (top & 0x3FF) % 900 + 100;
left = (left & 0x3FF) % 900 + 100;
right = (right & 0x3FF) % 900 + 100;
bottom = (bottom & 0x3FF) % 900 + 100;
System.out.println("[" + top + " " + left + " " + bottom + " " + right + "]");
}