Data Structures Homework 1, Spring 2000, 40 Points

Due: Wednesday, February 9, 2000, in class

  1. 10 points. Consider the following Java classes:
    public class A extends Object {
        A() { /* null constructor */ }
        public void printMe() { System.out.println("I'm first."); }
    }
    public class B extends A {
        B() { /* null constructor */ }
        public void printMe() { System.out.println("I'm second."); }
    }
    public class C extends B {
        C() { /* null constructor */ }
        public void printMe() { System.out.println("I'm third."); }
    }
    public class D extends C {
        D() { /* null constructor */ }
        public void printMe() { System.out.println("Rank doesn't matter, man."); }
        public static void main(String[] args) {
            B bill = new C();
            A george = new A();
            Object obj = new D();
            Object interim = new B();
            bill.printMe();
            george.printMe();
            ((C) obj).printMe();
            obj = bill;
            ((A) obj).printMe();
            obj = interim;
            ((B) obj).printMe();
        }
    }
    
    What is the output from calling the main() method of the D class?

  2. 10 points. Please provide a printout of the source file(s) and output from your doing project P-1.4 from the Goodrich-Tamassia text (as a Java warm-up). (Hint: you will need to look up in a Java book or visit http://www.javasoft.com/ to learn how to generate random numbers in Java.)

  3. 5 points. From the Goodrich-Tamassia text: R-2.5.
  4. 5 points. From the Goodrich-Tamassia text: R-2.6.
  5. 5 points. From the Goodrich-Tamassia text: R-2.24.
  6. 5 points. From the Goodrich-Tamassia text: C-2.3.