This exam is closed book, closed notes, closed classmates.
You have 75 minutes to complete it.
Please put all answers on the test sheets. Make sure your answer is
clearly marked and easily distinguished from work you do to get to the
solution. You should show your work for partial credit.
This especially applies to the program execution simulations.
I showed you in class how to do this in a way that will assist you
in getting the correct answer, as well as allow partial credit.
When done, please staple together your exams sheets and any paper you
use for work and place it face down on the lecture table up front.
Please print your name clearly below, and sign when you hand in
the exam, signifying your adherence to the honor code and attesting to
the work being yours alone.
Name (print CLEARLY) -------------------------------------------------------- Signed ---------------------------------------------------------------------
(a) making code as compact as possible to save storage (b) choosing variable names so they are meaningful to code readers (c) use of indentation to clearly show program structure (d) commenting major algorithm sections to explain the functionally (e) using named constants rather than having numbers scattered in the code answer: _______________
(a) multiple source files per program (b) information hiding and encapsulation (c) inheritance... class reuse (d) separation of compiler and execution engine (e) freedom from logical errors (f) polymorphism... name overloading answer: _______________
(a) the binary pattern used to represent a byte of computer memory
(b) the error numbers printed by the compiler when a program is
syntactically incorrect
(c) the byte lengths of different numeric types (short, int, long,
double, float)
(d) the executable intermediate language output by the javac compiler
answer: _______________
(a) allowing new classes to be written by using fields and methods
already written in other classes
(b) requiring that each variable used in a program be named according
to a naming standard (such as object fields begin with "_",
class names being with upper case, etc.)
(c) writing code without looking at the keyboard
(d) enforcing that only data of the correct declared type is ever
assigned to each variable
answer: _______________
(a) a view of a variable that allows it to take on different data
types at different times
(b) the portion of a program text where a variable name is visible
(c) use of the parameter list to determine which of several methods
with the same name is the one being called
(d) variable names must be chosen so they have descriptive value to
people reading the program
answer: _______________
answer: __________________________
final int MAX = 4;
int num = 1;
int k = 0; // loop index
while (k < MAX) {
num = num * k;
k++;
}
System.out.println(num);
answer: ________________
final int MAX = 6;
int num = 1;
int k = 1; // loop index
while (k < MAX) {
num = num * k;
k++;
}
System.out.println(num);
answer: ________________
class DemoConcepts {
int x = 0;
public int foo (int p) {
x = p;
int x = 5;
return x;
}
public static void main (String[] args) {
int p;
p = foo(12);
System.out.println("x: " + x+", p: "+p);
}
}
answer: ________________
int x = 5;
int f = 5;
if (x < 3) { x = x + 1; }
else if (x == 5) { x = x - 2 ; }
else if (x < 0) { x = x * 3; }
else { x = -8 ; }
if (f < 3) { f = f + 1; }
if (f == 5) { f = f - 2 ; }
if (f < 0) { f = f * 3; }
else { f = -8 ; }
System.out.println("x: " + x + ", f: " + f);
answer: ________________
public class NumCrunch {
public static int num = 99;
int k = 0;
NumCrunch() { k = num; num++; }
public int getK () { return k; }
public int getN () { return num; }
public double crunch (double num) {
return num * num;
}
}
public class SomeThing {
public static void main (String[] args) {
NumCrunch nc1 = new NumCrunch();
NumCrunch nc2 = new NumCrunch();
NumCrunch nc3 = new NumCrunch();
NumCrunch nc4 = new NumCrunch();
nc2.crunch(5);
nc3.crunch(8);
System.out.println( nc2.getK()+", "+nc1.getN() );
}
}
answer: ________________
class DemoStuff {
public static void main (String[] args) {
final int MAX = 8;
int[] info;
info = new int[MAX];
for (int i=0; i<MAX; i++) {
info[i] = 1;
for (int k=1; k<=i; k++) {
info[i] = info[i] * k;
}
}
System.out.println(info[4]);
}
}
answer: ________________