import tester.Tester; /* We wanted to represent an ancestor tree for a person, as far as we can remember, using 'unknown' for long forgotten ancestors. Here is the data definition in DrRacket: ;; An Ancestor tree (AT) is on of ;; -- 'unknown ;; -- Person ;; A Person is (make-person String AT AT) (define-struct person (name mom dad)) and here is an example: (define mary (make-person "Mary" 'unknown 'unknown)) (define robert (make-person "Robert" 'unknown 'unknown)) (define john (make-person "John" 'unknown 'unknown)) (define jane (make-person "Jane" mary robert)) (define dan (make-person "Dan" jane john)) That represents the following tree: Dan / \ Jane John / \ / \ Mary Robert ? ? / \ / \ ? ? ? ? The class diagram that represents this data definition looks like this: +------------------+ | +-------------+ | | | | | v v | | +-----+ | | | IAT | | | +-----+ | | / \ | | --- | | | | | ----------------- | | | | | | +---------+ +-----------+ | | | Unknown | | Person | | | +---------+ +-------------+ | | +---------+ | String name | | | | IAT mom |-+ | | IAT dad |---+ +-------------+ We replaced 'AT' with 'IAT" as in Java the union type will be represented as an interface, and we start the names of interface types with the letter I The code below shows how this class diagram and our examples can be translated into a represetation as Java classes and interfaces (Java class hierarchy): */ // to represent an ancestor tree interface IAT{ } // to represent an unknown member of an ancestor tree class Unknown implements IAT{ Unknown() {} } // to represent a person with the person's ancestor tree class Person implements IAT{ String name; AT mom; AT dad; Person(String name, IAT mom, IAT dad){ this.name = name; this.mom = mom;this.dad = dad; } } // examples and tests for the class hierarchy that represents // ancestor trees class ExamplesAncestors{ ExamplesAncestors(){} IAT unknown = new Unknown(); IAT mary = new Person("Mary", this.unknown, this.unknown); IAT robert = new Person("Robert", this.unknown, this.unknown); IAT john = new Person("John", this.unknown, this.unknown); IAT jane = new Person("Jane", this.mary, this.robert); IAT dan = new Person("Dan", this.jane, this.john); }