CSC 308 Sample Final Exam Answers




Question 1:
Customers       Prizes          Letters
=====================================================
Add ...         Add ...         Add ...
Delete ...      Delete ...      Delete ...
Change ...      Change ...      Change ...
Find ...        Find ...        Find ...
                                Generate ...
with no initial window below the menu bar

Rationale: this is a very simple menu-based UI, where all major commands are directly accessible from the menus.

Question 2:

Questions 3 and 5:

import java.util.Collection;
import java.util.List;

abstract class CustomerDB {
    Collection<CustomerRecord> data;

    abstract void add(CustomerRecord rec);
    abstract void delete(CustomerRecord rec);
    abstract void modify(CustomerRecord oldRec, CustomerRecord newRec);
    abstract Collection<CustomerRecord> search(String lastName);

    /*@
    ensures
        // Part a
        (\forall int i ; (i >= 0) && (i < \result.size()) ;
            \result.get(i).getZip() < \result.get(i+1).getZip())

                &&

        (\forall GeneratedLetter letter ; \result.contains(letter) ;

            // Part b
            match(sc).contains(letter.rec) &&
                (letter.rec.date > Calendar.todaysDate() - 182)

                    &&

            // Part c
            letter.numPrizes <= 5);
      @*/
    abstract List<GeneratedLetter> genLetters(SelectionCriteria sc);

    abstract Collection<CustomerRecord> match(SelectionCriteria sc);
}

class CustomerRecord {
    String firstName;
    String middleName;
    String lastName;
    String companyName;
    int age;
    String streetAddress;
    String city;
    String state;
    String country;
    int zipCode;
    int date;
    Collection<CustomField> customs;
}

class CustomField {
    String customFieldName;
    String customFieldValue;
}

class FormLetterDB {
    Collection<FormLetter> letters;
}

abstract class FormLetter {
    List<FormLetterComponent> body;
}

class FormLetterComponent {
    boolean isFillIn;
    String textOrFieldName;
}

class SelectionCriteria {
    StringPattern firstNamePattern;
    StringPattern middleNamePattern;
    StringPattern lastNamePattern;
    StringPattern companyNamePattern;
    StringPattern agePattern;
    StringPattern streetAddressPattern;
    StringPattern cityPattern;
    StringPattern statePattern;
    StringPattern countryPattern;
    StringPattern zipCodePattern;
    Collection<StringPattern> customFieldPattern;
}

class StringPattern {
    String str1;
    PatternOp op;
    String str2;
}

class IntegerPattern {
    int i1;
    PatternOp op;
    int i2;
}

enum PatternOp {
    LessThanSign,
    GreaterThanSign,
    EqualSign,
    RangeSign
}

abstract class GeneratedLetter {
    List<GeneratedLetterComponent> body;
    CustomerRecord rec;
    int numPrizes;

    abstract int getZip();
}

class GeneratedLetterComponent {
    boolean isFillIn;
    String textOrFieldName;
    String fieldValue;
}

class Calendar {
    static int todaysDate() { return 0; /* just to shut up gcc */ }
}

Question 4: