Name: ___________________________________________________
Umail Address: ______________________________@ umail.ucsb.edu
Circle one: 2pm 3pm 9am
Please write your name only on this page.
That allows me to grade your exams without knowing whose exam I am grading.
This exam is closed book, closed notes, closed mouth, cell phone off,
except for:
There are 100 points worth of questions on the exam, and you have 75 minutes to complete the exam.
A hint for allocating your time—on your first pass through the exam:
If you do that, after you complete your first pass through the exam in 50 minutes, you'll still have 25 minutes to:
There is more room on the next page for your answer if you run out of room here.
Extra space for your answer to question 1
Assume that we have the TideReading
class that you defined in question 1, with ONLY the constructor and the methods that were required for that problem.
What would the output of the following main program be? In addition to the output, provide a brief explanation.
public class E01q2 { public static void main(String [] args) { TideLevel a = new TideReading('H',3.4); TideLevel b = new TideReading('L',0.1); TideLevel c = new TideReading('L',0.1); TideLevel d = b; TideLevel e = c; System.out.println("a=" + a); if (a.equals(b)) System.out.println("awesome"); if (b.equals(c)) System.out.println("super"); if (b == d) System.out.println("puppy"); if (b.equals(e)) System.out.println("bowl"); if (a.equals(d)) System.out.println("parade"); if (b == c) System.out.println("party"); if (d == e) System.out.println("friends"); if (e.equals(d)) System.out.println("rock!"); }
Output (6 pts):
Explanation (4 pts):
a
in the main program above. Is the variable a
on the stack, or on the heap? Circle one: stack heapa
. /** Feed the dog. The food in the DogBowl passed in will be eaten, and the health of the dog will increase depending on the nutrition level of the dog food that was in the bowl (if any). @param db A bowl of Dog Food. */ public void feed(DogBowl db) { DogBowl db = new DogBowl(); this.increaseHealthBy(db.eat()); }
javadoc
is a "target" or a "task" in Ant. You want to keep the peace between Mary and Fred, because you share a crowded apartment with them on Del Playa, and when they aren't happy, no-one in the house is happy. #include
directive in C/C++ vs. the import
statement in Java.
#include
and import
similar in the role they play in the language?#include
and import
different in how they are actually implemented? There are more questions on the back page—dont forget them!
For the remaining questions, you only need to write individual fragments of java code.
Don't worry about putting your code inside a method or a class.
x
that is NOT of a reference type.
y
that is NOT of a primitive type.Dog
is a class that represents a Dog. Declare a variable called kennel
that can store more than one reference to a Dog object. Choose a type for kennel
so that it can automatically grow as needed if the number of Dog
objects grows arbitrarily large.Total points: ?