Name: ___________________________________________________
Umail Address: ______________________________@ umail.ucsb.edu
Circle one: 6:30pm 7:30pm
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:
System.out.println("rs = " + rs);
when rs
is of type RadioStation.
System.out.println("rs = " + rs);
should be:rs = [KCSB, FM 91.9]
. new RadioStation("KTMS",990)
, the result should be: rs=[KTYD, AM 990]
, or rs=[KTYD, AM 990.0]
(Don't worry about whether the .0 prints or not—I'll accept your answer either way.)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 RadioStation class that you defined in question 1, with ONLY the constructors and 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) {
RadioStation a = new RadioStation();
RadioStation b = new RadioStation();
RadioStation c = a;
System.out.println("red");
if (a == b)
System.out.println("orange");
if (a.equals(b))
System.out.println("yellow");
if (a == c)
System.out.println("green");
if (a.equals(c))
System.out.println("blue");
}
}
Output (5 pts):
Explanation (5 pts):
Now, assume, just like in question 2 that we have the RadioStation class, but that this time we have added one additional methods as shown below.
public boolean equals(Object o) { double tol = 0.01;
if (! (o instanceof RadioStation) ) return false; RadioStation other = (RadioStation) o; return (other.getCallSign().equals(this.getCallSign()) &
Math.abs(other.getFrequency() - this.getFrequency()) < tol ); }
public class E01q2 {
public static void main(String [] args) {
RadioStation a = new RadioStation();
RadioStation b = new RadioStation();
RadioStation c = a;
System.out.println("red");
if (a == b)
System.out.println("orange");
if (a.equals(b))
System.out.println("yellow");
if (a == c)
System.out.println("green");
if (a.equals(c))
System.out.println("blue");
}
}
Output (5 pts):
Explanation (5 pts):
Additional Question (5 pts): In the equals method shown above, there is a single &
used to indicate boolean and instead of a double &&
like you may be used to. What is the effect, in this program of using &
vs. &&
? Explain briefly:
There are more questions on the back page—dont forget them!
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.Foobarable
is an interface. Which line of code is correct?public class Geegaw extends Foobarable
{ ...public class Geegaw implements Foobarable
{ ...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.
p
that is NOT of a reference type.q
that is NOT of a primitive type.Total points: ?