©2005 Felleisen, Proulx, et. al.

4.5  Problem

The following class diagram defines data that represents web pages.

        +----------------------------------+
        |                                  |
        v                                  |
+---------------+                          |
| WebPage       |                          |
+---------------+                          |
| String header |                          |
| ALoHTML body  |--+                       |
+---------------+  |  +----------------+   |
                   v  v                |   | 
              +---------+              |   |             
              | ALoHTML |              |   |
              +---------+              |   |
              +---------+              |   |
                 / \                   |   |
                 ---                   |   |
                  |                    |   |
       -------------------             |   |
       |                 |             |   |
  +----------+     +--------------+    |   |
  | MTLoHTML |     | ConsLoHTML   |    |   |
  +----------+     +--------------+    |   |
  +----------+  +--| AHTML first  |    |   |
                |  | ALoHTML rest |----+   | 
                |  +--------------+        |
                v                          |  
       +-------------+                     |     
       | AHTML       |                     |     
       +-------------+                     |    
       | String word |                     |      
       +-------------+                     |      
             / \                           |    
             ---                           |    
              |                            |    
     ----------------                      |   
     |              |                      |   
  +------+    +------------+               |   
  | Word |    | Link       |               |    
  +------+    +------------+               |  
  +------+    | WebPage wp |---------------+ 
              +------------+  

  1. Translate this data definition into Java classes and make examples of the data.

  2. Design the method allWords, which produces a list of all words in the web page (all strings, including the header string).

  3. Design 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:

  4. Design the method occurs, which determines whether the given word occurs in the web page or its embedded pages.