600.226 Assignment 1
To be handed in at the beginning of class on Sep 20.
1. 5 points
What does the following code fragment produce? Explain.
/* Begin Code fragment */
class classclass {
class A {
A() { System.out.println("I am A"); }
}
class B {
B() { System.out.println("I am B"); }
}
class C extends A {
public B b;
C() { System.out.println("I am C"); }
C(int p) { System.out.println("I am C with " + p); }
}
void dummy() {
C c1;
C c2 = new C(5);
}
}
class classmain {
public static void main(String argv[]) {
classclass c = new classclass();
c.dummy();
}
}
/* End Code fragment */
2. 5 points
What does the print statement in the following code fragment produce?
/* Begin Fragment */
int i;
for(i=0; i<10; i++);
System.out.println(i);
/* End fragment */
3. 5 points
Find the value of the given expressions (say *illegal*, if applicable):
int a = 2, b = 5, c = 0, d = 3;
Expression Value
b % a
a < d
(c != b) && (a > 3)
a/b > c
a*b > 2
4. 10 points
Write a program to generate the value of e.
e = 1 + 1/1! + 1/2! + 1/3! + 1/4! + ...
Let the user specify the number of terms used in the evaluation.
5. 10 points
Goodrich and Tamassia, 2ed, problem C-2.3
6. 5 points
Goodrich and Tamassia, 2ed, Problem R-2.10
7. 10 points
Goodrich and Tamassia, 2ed, Problem P-2.3