[ answers in web view ]
Name: _______________________________
Student ID: _______________________________

Total points: 70
  1. Describe the MVC design pattern, and give an example of each component of the MVC system. [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
  2. What does the acronym CRUD mean, in reference to database systems? Describe an example application in which CRUD might be useful. [4]
    Create, Read, Update, Destroy: e.g., a student enrolment database: add a new student to the system, print out information on an existing student, change a student's information (name, GPA, etc.), and remove a student from the system (e.g., after graduation).
  3. Consider Java interfaces and abstract classes.
    1. What is an interface in Java? Describe an example. [3]
      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.
    2. What is an abstract class? Describe an example. [3]
      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.
    3. Describe the differences between interfaces and abstract classes. [3]
      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.
  4. What is the effect of the static keyword on attributes and methods? Why must main() be declared static? Describe another example of an appropriate use of 'static' on an attribute or method. [5]
    Static members belong to the whole class, rather than to each instance. Static methods can be invoked from the class without needing to instantiate the class. main() has to be static because when it is run no objects have been instantiated yet. The String library has a number of static utility methods, e.g., String.format(). Another example is the constant Math.PI.
  5. What is event-driven programming? Describe an example in detail. [3]
    Action happens in response to events. Events may be user-triggered (e.g., click on button, or press a key), or may be synthetic (e.g., timer). Event handlers/listeners are connected to each object which may send events, and the listeners define what should happen when an event is received (i.e., the callbacks). E.g., when a user clicks on a JButton, an ActionEvent is sent. If the JButton has an ActionListener set, then that listener's actionPerformed() method is called. When the callback completes, control returns to the main event loop, which waits for the next event.
  6. Name and briefly describe the features of at least 4 Swing widgets (i.e., subclasses of JComponent). If you can't remember the exact name of the class, describe the widget in as much detail as you can. [5]
    Many to choose from: JPanel, JFrame, JButton, JCheckBox, JComboBox, JRadioButton, JLabel, JTextField, JPasswordField, JTextArea, JMenu, JMenuItem, JSlider, JProgressBar, ...
  7. Consider the UML class diagram below (from AgileData.org).
    1. Describe all the relationships involving the Seminar class (top right) in the diagram. Consider multiplicity. [6]
      Each Seminar has at least one SeminarEnrollment object (which references a Student). There can be any number of students on the waitlist. There can be either 0 or 1 professors instructing the Seminar. The Seminar is an offering of a Course (although there can be multiple Seminars for one Course).
    2. What is the role of the SeminarEnrollment class? Why not just have a direct relationship between Student and Seminar? [3]
      The SeminarEnrollment object holds the info for a registered Student in a Seminar: e.g., that Student's marks. If the SeminarEnrollment class did not exist, the marks would have to be stored either in the Student (disconnected from the course) or in the Seminar (disconnected from the Student).
    3. What does the looping arrow below and to the right of the Professor class mean? Consider multiplicity. [3]
      Professors can mentor other Professors: one would be the advisor, and the other would be the associate. Each Professor can be the advisor for any number of associates, but each associate may have at most one advisor.
  8. On a separate page, declare simple Java classes and sketch a UML class diagram to formalize the following set of statements. Declare and diagram every (non-primitive) class used. Implementations of methods are not required.[10]
    abstract class Person {
    	String name;
    	int phoneNumber;
    abstract class TWUPerson extends Person {
    	int yearOfContact;
    class Student extends TWUPerson {
    	float GPA;
    	void registerForClasses();
    class Employee extends TWUPerson {
    	float salary;
    class Faculty extends TWUPerson {
    	void teachClass();
    class Staff extends TWUPerson {}
    Student joe = new Student();
  9. Consider Java copy constructors.
    1. What is a copy constructor, and what is it used for? [3]
      A copy constructor performs deep copy: the one parameter is another object of the same type, and the copy constructor copies attributes from the other object into the current object.
    2. On a separate page, implement in Java a Song class with attributes title (String), artist (String), and year (int). Write three constructors: one with no parameters, one with three parameters (String, String, float), and one that is a copy constructor. Remember that 'String' is a class in Java, not a primitive type. [5]
      See Song.java.
  10. The task in this programming problem is to implement a complete Java program using serialized I/O on the Song class you defined in the previous question.

    Your program should open the file "song.obj", which you can assume contains one serialized Song (e.g., generated by your program previously). Read in the Song object, append the year in parentheses to the title, and store the object back to the same file.

    For example, if the file "song.obj" previously contained a song with title "Amazing Grace", artist "John Newton", and year 1779, then after your program runs, the file should contain a song object that has a title of "Amazing Grace (1779)".

    You do need to worry about exceptions that could be raised. You do not need any keyboard/console I/O. You may need to modify your Song class slightly. Docstrings and comments are not necessary but may be good for partial credit. Some standard Java classes you may find helpful: File, FileInputStream/FileOutputStream, ObjectInputStream/ObjectOutputStream. Don't worry about importing (i.e., assume all relevant imports are already done). [10]
    See SongTitle.java.