[ answers in web view ]
Name: _______________________________ K E Y
Student ID: _______________________________

Total points: 70
  1. Compare and contrast object-oriented programming with procedural programming. [4]
    Procedural programming is action-oriented: the code is a sequence of procedures, and the data structures are passed as parameters to the procedures. The focus is on the 'verbs'. In contrast, object-oriented programming is data-oriented: code is organized into classes, centred around objects, and the procedures are treated as methods within each class. The focus is on the 'nouns'.
  2. Explain what the JDK and JRE are and contrast them. [3]
    Java Runtime Environment
    what you need to run (other people's) Java programs: the Java virtual machine (command line: java).
    Java Development Environment
    what you need to compile (make your own) Java programs: javac compiler.
  3. Describe and contrast the eight Java primitive types. [6]
    boolean type, just true and false
    a Unicode character
    an integer represented with 1 byte
    an integer represented with 2 bytes
    an integer represented with 4 bytes
    an integer represented with 8 bytes
    a real value represented with 4 bytes
    a real value represented with 8 bytes
  4. Describe the MVC design pattern [4]
    Data structures and methods to interact with the data. e.g., 2D array of letters for word-search
    Display/output, summary of the data, statistics, etc. e.g., Swing labels, text output
    Input/control from the user or other programs. e.g., Swing buttons, keyboard input
  5. Explain and contrast method overloading with method overriding. [4]
    multiple versions of the same method (same name) but with different number/types of parameters.
    a method defined in a subclass overrides a method of the same name in the superclass.
  6. What is an abstract superclass? What would you use one for? Give an example of such a situation (no code required, just describe the situation). How do you declare a class to be abstract? [4]
    An abstract class is not meant to be instantiated directly. An abstract superclass can be used as a way of organizing its subclasses under one category. For example, Dog, Cat, and Cow all are within the Mammal category. It makes sense to have specific instances of Dog, Cat, and Cow, but not of Mammal. Mammal is the abstract superclass. In Java, an abstract class is declared with the 'abstract' keyword. Concrete subclasses must override all abstract functions and provide bodies to them.
  7. What is a Java class interface? Think of an example and describe it (need not be one standard to Java). When might a designer choose to define an interface rather than an abstract superclass? [5]
    An interface is a named set of methods, for instance the ActionListener interface specifies the actionPerformed() method and advertises that a class knows how to respond to action events. Interfaces specify functionality, i.e., what a class knows how to do. Abstract superclasses specify identity, i.e., what a class is. Multiple classes that inherit from different superclasses may implement the same interface, but in Java multiple inheritance is not permitted.
  8. Describe and contrast the four options we have in Java for access modifiers on attributes/methods. [4]
    only methods in this class can access
    (no modifier)
    methods in this class and this package can access
    also subclasses can access
    anyone can access
  9. Name and briefly describe at least five Swing widget classes. [4]
    JLabel, JTextField, JPasswordField, JButton, JCheckBox, JRadioButton, JComboButton, JTextArea, JScrollPane, ...
  10. What basic shapes can Java's Graphics class draw? Name at least four. Also, name and describe the basic functions used to draw them. [4]
    drawLine(), drawRect(), drawOval(), drawArc(), drawPolyline(), drawPolygon(), draw3DRect(), drawRoundRect(), ...
  11. In computer graphics (e.g., Java2D), what is clipping? [4]
    Clipping is removing primitives -- or portions of primitives -- that lie outside the current 2D viewport. This may involve changing the shape of primitives to ensure they do not draw outside the viewport.
  12. Consider a student enrolment database like what we have at TWU: it holds students' personal information, transcripts, current enrolment, advising notes, etc. Design a use-case chart for such a system. (You have a fair amount of freedom in how to design the system.) [6]

  13. Declare simple Java classes and sketch a UML class diagram that formalizes the following set of statements. Declare and diagram every (non-primitive) class used. Implementations of methods are not required.[8]

    interface Drawable {
    	void draw();
    abstract class Shape implements Drawable {
    	private Colour lineColour;
    	private Colour fillColour;
    	public void draw() {};
    class Rectangle extends Shape {
    	private float width;
    	private float height;
    class Oval extends Shape {
    	private float radius;
    	private float eccentricity;
    class Dot extends Shape {}
    class Square extends Rectangle {}
    class Circle extends Oval {}
  14. Write a Java class that takes a list of integers and outputs two columns of numbers: the first column shows the distinct numbers in the list; the second column shows the frequency with which that integer shows up in the list. (This is a frequency table.) For example, if the input list was (-12, 2, 0, 5, 2, 2, -12), then the output could be:
    N    Count
    -12  2
    2    3
    0    1
    5    1
    (Formatting/spacing of the output is not too important, and the output does not need to be in sorted order.) You do not need to write a complete program that tests this (and you do not need keyboard-interactive user input), just a class that provides a function to do this. Docstrings and comments are not necessary but may garner partial credit. [10]
    See FreqTable.java.