CIS 1068.002 Fall 2010 FIRST MIDTERM The total number of points is 160 1. (10) What is the difference between checked and unchecked exceptions? Give also an example of each. 2. (15) Write the method public static int getInRange(int low, int high) that prompts the user to enter an integer in the range [low,high] and returns only when such a value has been entered. Make sure that the method will not crash on bad input. 3. (10) B is a class that extends class A. x is a static data member of A. x is an instance data member of B. Assume everything is public. In a third class C, no relation to A or B, how do I refer to the x of A and how to an x of B? 4. (10) Bring the six steps of creating a GUI into the right order: Add components, apply layout, register listeners, show it to the world, import packages, set up top level container 1._______________________ 4._________________________ 2._______________________ 5._________________________ 3._______________________ 6._______________________ 5. (15) When I click on a Button button, I want to execute the method foo of object joe and the method moo of object jim [foo and moo are with no parameters and return no value]. Write fragments of code [i.e. not a whole program] that will carry out this behavior. 6. (10) Give an example of two data structures that are deep equal but not shallow equals. 7. (10) We say that a function f(n) is Big-O of g(n). What does it mean? 8. (15) Write the method filter that given an Arraylist a of elements of type E and an element b of type E returns an ArrayList consisting of all the elements of a that are not equal to b. 9. (5) What is required of a class that implements the Iterable interface? 10.(5) What is required of a class that implements the Comparable interface? 11.(5) What is required of a class that implements the Iterator interface? 12.(10) Implement the method public static int sum(Collection c) which returns the sum of all elements of c. 13.(10) Implement recursively the method public static void printAll(String s) which prints out, one per line, all the characters of s. 14.(15) Determine the Big-O complexity of the Tower of Hanoi program. Be as precise as you can. 15. (15) We have discussed Singly Linked Lists. Specify the instance data memebers of a. The Node class b. The SLList class c. The iterator class used for the SLL list