20-CS-694 Advanced Programming Techniques Spring 2012
Hints for Homework Assignment 2

Interfaces, Exceptions, Graphics, Animation, Threads, Reflection, Networking, RMI, JDBC, JNI

Exceptions for Control - Declarative Style

Due: April 17, 2012 (submit instructions: here)

Define some helper functions
    Define some helpers that will make checking efficient. For example, define a function called distinct that takes as input a set of variables and returns true iff all the variables of the set have distinct values. Apply this function in an assert_ after each set of 5 Choose statements mentioned on the previous slide - but only on the variables of those Choose statements - this is best handled by putting all 25 variables in a 5x5 array so that distinct can be applied to a row at a time where rows are indexed on variable type (pet, smoke, drink, house, position).

Another helper might be the function 'leftOf' which takes two house names as input and returns true iff the first house is to the left of the second house in the argument list.

Another helper might be the function 'neighbor' which returns true iff the two named people in the argument list are in adjacent houses. The 'neighbor' function can become part of the constraint set for smoking, drinking, and position variables.

Put all the helpers in a class called BooleanExpression and package the constraints associated with each class of variables into a class that subclasses BooleanExpression. The result will be prettier code.

More Help