Exercise 6.1 Given a UML diagram to represent the descendant tree, and the code that implements the method which counts the number of people in the descendant tree, develop the following methods:
blueEyes, which determines whether there is a person with blue eyes in the descendant tree.
countBlueEyes, which count the number of persons with blue eyes in the descendant tree.
find, which produces the year of birth for a person with the given name, or 0, if no person in the tree has this name.
children, which produces a list of children for a person with the given name, or an empty list of children, if a person with this name is not in the tree.
Add the missing templates to all classes and continue to develop the templates as you work on this problem. Add one more generation (at least three grandchildren) to the test cases.
Exercise 6.2 A GUI Component is one of the following:
BooleanView
TextFieldView
OptionsView
ColorView
Table
Each
component contains a label and some additional data.
The data for
a Table is one of
empty
list of Rows
A Row is one of
empty
list of Components
Data for each of the remaining components is the default value to be displayed, specified as a String, and the preferred width and height.
Draw the UML diagram for this collection of classes.
Develop the templates for methods needed to count the number of primitive GUI elements in a given GUI Component.
Develop the templates for the methods needed to determines the height of a given GUI Component. The height of the table is the sum of the heights of the Rows. The height of a Row is the maximum size of components in the list of Components.
Note: Do not write the code!!!
Exercise 6.3 A WebPage consists of a
String header,
and a Body b.
A Body is a list of HTML elements.
A
HTML element is either
a String word
or a Link.
A Link consists of
a String word
and a WebPage.
Draw the UML diagram for the collection of classes that represent web pages.
Develop the classes.
Develop the method allWords, which produces a list of all words in the web page
Develop the method pages, which produces the list of immediate words on a page. That is, it consumes a WebPage and produces a list of String. An immediate word on a list of HTML elements is defined as follows:
an HTML element that is a word is the immediate word
for an HTML element that is a Link, the method extracts the word from the Link.
Develop the method occurs, which determines whether the given word occurs in the web page or its embedded pages.