// Data Definition: IntList := new Empty() + new Cons(int, IntList) abstract class IntList { /** Returns String representation of this without enclosing parens. */ abstract String toStringHelp(); } class Empty extends IntList { static Empty ONLY = new Empty(); // singleton pattern /* constructor */ private Empty() {} String toStringHelp() { return ""; } public String toString() { return "()"; } } class Cons extends IntList { int first; IntList rest; /* constructor */ Cons(int f, IntList r) { first = f; rest = r; } /* accessors */ int getFirst() { return first; } IntList getRest() { return rest; } public String toString() { return "(" + first + rest.toStringHelp() + ")"; } String toStringHelp() { return " " + first + rest.toStringHelp(); } }