Ryerson University
School of Computer Science
CPS209 Term Test #1B : Winter 2006
Worth = 15%; Time limit = 50 minutes; No aids

Name:____________________________________ Student #: ______________________

Section #: ______________________
Note: there are several meanings of the word interface, but in this exam the only meaning that applies is the java construct of which Comparable is a typical example.
A. (1 point each)
  1. Polymorphism. Consider the call x.getMeasure() in the DataSet class that we studied as an example, where x is of type Measurable, an interface.
  2. Interface. List two characteristics of methods in an interface.
  3. Interface. Name two classes in the Java libary which use interfaces, and also name in each case the interface used.
  4. Inner class: Give two reasons why one might write a class as an inner class rather than a top-level class?
  5. drawing: Write a panel's paintComponent which draws a circle with two diameter lines shown, one vertical and one horizontal.
              public void paintComponent(Graphics g)
                  Graphics2D g2 = (Graphics) g ;

B. (5 points) Write a static method which finds and returns the maximum in an array of objects passed as a parameter x. Base your method on the interface Measurable which has method double getMeasure(). If x is null or an empty array, return null.

C. (5 points) Write a class which could be used to make a listener object for a Timer. Every second "tick" the listener should print the current time (obtained from a Date object using the toString() method), and on the other "ticks" the listener should print "-------".