Midterm
2 Information
Time: Thursday, 4/8, 5-7pm
(unless you’ve contacted me about a conflict)
Place: 145 Birge
Bring: Your student ID and some pencils
What’s
the exam format?
The format will be the same as last time. This exam covers primarily the material
after the first midterm. But as you can
tell, a lot of this material depends on earlier concepts, so it’s not like you
can totally forget everything you’ve studied already.
How
can you prepare?
The true-false and multiple
choice questions focus on Java terminology and facts from chapters 5,6,8, and
9, and on understanding small pieces of code.
The written section will require you to write small pieces of code that
solve specific problems, or possibly to write explanations of concepts. Expect questions related to any assignments
and class examples you’ve seen so far, and about all the term definitions and
Java rules that we talked about in class since the first exam. Here are some suggestions for studying:
Terms:
sequential
execution
control
statement
selection
statement
repetition
statement
boolean
expression
relational
operator
boolean
operator
arithmetic
exception
null
pointer exception
short-circuit
evaluation
flag
nested
statements
increment/decrement
operators
dangling
else problem
DeMorgan's
law
defensive
programming
count-controlled
loop
sentinel-controlled
loop
priming
read
infinite
loop
overflow
error
off-by-one
error
pretest
loop
posttest
loop
control
variable
ASCII
Unicode
character
string
out-of-bounds
exception
exception
thrower
exception
catcher
exception
propagator
checked
exception
unchecked
exception
runtime
exception
1) Evaluate the
following boolean expressions:
a) 6 == 6 || x < y
b) 2 < 4 && (false || 5 <= 4)
c) x <= y && !(z != z) || x > y
d) x < y || z < y && y <= z
2) Fill in the
method so it returns true if at least two of the parameters are true.
public boolean
areAnyTwoTrue(boolean a, boolean b, boolean c) {
}
3) What's the value of x after
these loops?
int x=0, i=0; int
x = 0;
while (i < 6) { do
{
x += i; x
-= 10;
i += 2; } while (x > 0);
}
4) Fill in the method so it
prints the location of each Trash object in the TrashList.
public void
printTrash(TrashList list) {
}
5) Fill in the method so it inputs a double without ever throwing an
IOException or a NullFormatException.
public double
getDouble(BufferedReader buf) {
}
6) Fill in the method so it returns a new
String containing only every other letter from the parameter String.
public String
alternate(String str) {
}