Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Chapter 14 Ancestor Tree
Chapter Objectives <ul><li>Provide a case study example from problem statement through implementation </li></ul><ul><li>De...
Ancestor Trees <ul><li>An ancestor tree is a tree that represents a person’s biological heritage </li></ul><ul><li>A theor...
Ancestor Trees <ul><li>For this case study we will create a graphical implementation of an ancestor tree with the followin...
Ancestor Trees <ul><li>In addition, we will also keep track of the siblings for each of the individuals in the tree </li><...
Ancestor Tree - Design <ul><li>Our system is made up of four high-level components </li></ul><ul><ul><li>The driver </li><...
Ancestor Tree - Design <ul><li>In this case, our ancestor tree is an obvious refinement of a binary tree </li></ul><ul><li...
FIGURE 14.1  The BinaryTreeADT interface
AncestorTree - the Person Class <ul><li>The Person class must provide variables to represent </li></ul><ul><ul><li>First n...
AncestorTree - the Person Class <ul><li>The Person class must provide a constructor, a compareTo method (implements Compar...
AncestorTree - the AncestorTreeNode Class <ul><li>The AncestorTreeNode class is designed to serve as a container for the w...
AncestorTree - the AncestorTree Class <ul><li>The AncestorTree class extends the ArrayBinaryTree class </li></ul><ul><li>T...
AncestorTree - the AncestorTree Class <ul><li>Since the AncestorTree class extends the ArrayBinaryTree class, it also inhe...
AncestorTree - the AncestorGUI Class <ul><li>The AncestorGUI class provides a graphical, direct-manipulation interface for...
AncestorTree - the AncestorDemo Class <ul><li>The AncestorDemo class serves as the driver for our system </li></ul><ul><li...
FIGURE 14.2   User interface design for Ancestor Tree system
FIGURE 14.3   UML description of Ancestor  Tree system
Upcoming SlideShare
Loading in …5
×

Ch14 Ancestor Tree

682 views

Published on

Published in: Business, Technology
  • Be the first to comment

  • Be the first to like this

Ch14 Ancestor Tree

  1. 1. Chapter 14 Ancestor Tree
  2. 2. Chapter Objectives <ul><li>Provide a case study example from problem statement through implementation </li></ul><ul><li>Demonstrate how a binary tree can be used to solve a problem </li></ul>
  3. 3. Ancestor Trees <ul><li>An ancestor tree is a tree that represents a person’s biological heritage </li></ul><ul><li>A theoretical ancestor tree is a perfectly balanced, inverted, binary tree </li></ul>
  4. 4. Ancestor Trees <ul><li>For this case study we will create a graphical implementation of an ancestor tree with the following functional requirements: </li></ul><ul><ul><li>enter a person as a starting point </li></ul></ul><ul><ul><li>enter a parent for any individual in the tree that does not already have two parents listed </li></ul></ul><ul><ul><li>find a person in the tree (or determine they are not in the tree) </li></ul></ul><ul><ul><li>remove an individual from the tree </li></ul></ul><ul><ul><li>remove an ancestral line from the tree </li></ul></ul><ul><ul><li>remove all of the individuals from the tree </li></ul></ul><ul><ul><li>return the height of the tree </li></ul></ul>
  5. 5. Ancestor Trees <ul><li>In addition, we will also keep track of the siblings for each of the individuals in the tree </li></ul><ul><li>Since the tree itself simply represents parents and a single child, the siblings will have to be stored separately </li></ul><ul><li>One additional long-term goal (programming project 14.6) is to allow the user to save and retrieve their work from a file </li></ul>
  6. 6. Ancestor Tree - Design <ul><li>Our system is made up of four high-level components </li></ul><ul><ul><li>The driver </li></ul></ul><ul><ul><li>The graphical user interface </li></ul></ul><ul><ul><li>The class that we will use to represent an individual </li></ul></ul><ul><ul><li>The ancestor tree implementation itself </li></ul></ul>
  7. 7. Ancestor Tree - Design <ul><li>In this case, our ancestor tree is an obvious refinement of a binary tree </li></ul><ul><li>Thus, this example fits the concept of re-use based development </li></ul><ul><li>Our BinaryTreeADT that we defined in chapter 12 provides most of the functionality that we will need </li></ul><ul><li>Since one of the long-term goals of this project is to save and retrieve our work from a file, we choose to extend an array implementation of a binary tree </li></ul>
  8. 8. FIGURE 14.1 The BinaryTreeADT interface
  9. 9. AncestorTree - the Person Class <ul><li>The Person class must provide variables to represent </li></ul><ul><ul><li>First name </li></ul></ul><ul><ul><li>Last name </li></ul></ul><ul><ul><li>Date of birth </li></ul></ul><ul><ul><li>Date of death </li></ul></ul><ul><ul><li>Occupation </li></ul></ul><ul><ul><li>Address </li></ul></ul>
  10. 10. AncestorTree - the Person Class <ul><li>The Person class must provide a constructor, a compareTo method (implements Comparable), and a toString method </li></ul>
  11. 11. AncestorTree - the AncestorTreeNode Class <ul><li>The AncestorTreeNode class is designed to serve as a container for the whatever type of object we are storing in the ancestor tree </li></ul><ul><li>This class provides a double ordered list to keep track of siblings and provides an element variable to store the person (or other animal) represented by this node </li></ul><ul><li>This class also provides a constructor, a method to add a sibling, and a toString method </li></ul>
  12. 12. AncestorTree - the AncestorTree Class <ul><li>The AncestorTree class extends the ArrayBinaryTree class </li></ul><ul><li>The class provides a variable to represent the height of the tree </li></ul><ul><li>The class provides methods to: </li></ul><ul><ul><li>Add an element </li></ul></ul><ul><ul><li>Remove an element </li></ul></ul><ul><ul><li>Remove the left or right ancestral line </li></ul></ul><ul><ul><li>Return the height of the tree </li></ul></ul><ul><ul><li>Remove all of the elements </li></ul></ul><ul><ul><li>Find an element </li></ul></ul><ul><ul><li>Determine if an element exists in the tree </li></ul></ul>
  13. 13. AncestorTree - the AncestorTree Class <ul><li>Since the AncestorTree class extends the ArrayBinaryTree class, it also inherits all of the methods of that class including iterators and the toString method </li></ul>
  14. 14. AncestorTree - the AncestorGUI Class <ul><li>The AncestorGUI class provides a graphical, direct-manipulation interface for the ancestor tree </li></ul><ul><li>This allows the user to click directly on the person they wish to edit </li></ul>
  15. 15. AncestorTree - the AncestorDemo Class <ul><li>The AncestorDemo class serves as the driver for our system </li></ul><ul><li>It simply creates an instance of the AncestorGUI class and calls its display method </li></ul>
  16. 16. FIGURE 14.2 User interface design for Ancestor Tree system
  17. 17. FIGURE 14.3 UML description of Ancestor Tree system

×