COP 3530 EXAM 1 February 4, 1998 Kraynek Name:_______________ 10 points 1. Consider the following declarations: class A {...} A anA = new A(..); class B extends A {...} B aB = new B(..); interface C {...} C aC; class D implements C {...} D aD = new D(..); In the following segment, which of the following statements will cause a compile error and which a run-time error? anA = aB; aB = anA; aB = (B)anA; anA = new A(..); aB = (B)anA; aC = new C(..); aC = aD; 10 points 2. Write the code for the following method in the LinkedList class from Assignment Two. /** if x is in the list delete it */ public void removeElement(Object x) { } 15 points 3. Write a Java method to extract 'words' from a String variable file and store them in a linked list with a list head pointed to by Words. Store ALL words not just unique ones. Use the following declarations and assume that Words has been initialized and delimiters define 'words'. Class ListNode { public ListNode(Object element, ListNode next) { this.element = element; this.next = next; Object element; ListNode next; } public void getWords( ListNods Words, String file, String delimiters); 4. Consider the interface Stack: public interface Stack { boolean isEmpty(); void makeEmpty(); void push(Object x); void pop(); Object top(); } Write the code for an implementation of Stack using the Vector class. Class Vector // A Constructor public Vector(int initialCapacity); // Some Methods public final void addElement(Object obj); public final Object elementAt(int index); public final void insertElementAt(Object obj, int index); public final boolean isEmpty(); public final void removeAllElements(); public final void removeElementAt(int index); public final void setElementAt(Object obj, int index); public final void setSize(int newSize); public final int size(); }