©2005 Felleisen, Proulx, et. al.

Containment in Unions


                               Bob
                               1917
                                |
    +--+--+   +--+--+     +--+--+
       |         |           |
    Angela    Robert       Annie
     1936      1935        1938        
       |         |           |         
       +----+----+           +----+----+
            |                     |
          Janet                 Paul
          1958                  1956
            |                     |
            +----------+----------+
                       |
                     Peter 
                     1980

Figure 4: A family tree

1.8  Problem (5.3.1)

Consider the following problem:

Develop a program that helps with recording a person's ancestor tree. Specifically, for each person we wish to remember the person's name and year of birth, in addition to the ancestry on the father's and the mother's side, if it is available.
See figure 4 for an example of the relevant information.

Develop the class diagram and the class definitions to represent ancestor family trees. Then translate the sample tree into an object. Also draw your family's ancestor tree as far as known and represent it as an object.

1.9  Challenge Problem

The figure 5 and figure 6 represent parts of two different transit systems. The system is designed so that the traveler cannot travel through a station more than once.

Design the class hierarchy which represents this data. Show your design in the form of a class diagram. Make examples of data that represent the transit system shown in figure 5.


MTA Transit System: simple schematic diagram, not to scale.

                +-+
                |H|
                +-+
                 |
                 |
                 |
                 v
   +-+          +-+          +-+ 
   |K|-~-~-~-~->|P|-~-~-~-~->|B|
   +-+          +-+          +-+ 
                 |               
                 |          
                 |     
                 v           
   +-+          +-+                      +-+ 
   |F|-.-.-.-.->|D|-.-.-.-.-.-.-.-.-.-.->|S|
   +-+          +-+                      +-+ 
 
  
  -~-~-~-~->   green line        |
  -.-.-.-.->   blue line         |
                                 v
                             red line

Locations (in real life):

B	220, 100
D	200, 180
F	100, 200
H	100,  40
K	 60, 120
P	140, 120
S	300, 140

Figure 5: A simple transit system diagram


MTA Transit System: schematic diagram, not to scale.

                +-+
                |H|
                +-+
                 |
                 |
                 |
                 v
   +-+          +-+          +-+         +-+            +-+
   |K|-~-~-~-~->|P|-~-~-~-~->|B|~-~-~-~->|N|.. .. .. ..>|M|
   +-+          +-+          +-+         +-+            +-+
                 |                        ^ 
                 |                        :
                 |                        :
                 v                        :
   +-+          +-+                      +-+            +-+
   |F|-.-.-.-.->|D|-.-.-.-.-.-.-.-.-.-.->|S|-.-.-.-.-.->|W|
   +-+          +-+                      +-+            +-+
                 |                        ^
                 |                        :
                 |                        :
                 v                        :
                +-+                      +-+
                |Q|                      |C|
                +-+                      +-+


  
  -~-~-~-~->   green line        |
  -.-.-.-.->   blue line         |
  .. .. ..>    yellow line       |
                                 v
                             red line

Locations (in real life):

B	220, 100
C	300, 220
D	200, 180
F	100, 200
H	100,  40
K	 60, 120
M	340,  40
N	300,  40
P	140, 120
Q	260, 220
S	300, 140
W	360, 180

Figure 6: A transit system diagram