©2005 Felleisen, Proulx, et. al.
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 |---------------+ +------------+
Translate this data definition into Java classes and make examples of the data.
Design the method allWords
, which produces a list of
all words in the web page (all strings, including the header string).
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:
an HTML
element that is a Word
the
method extracts the word
from the Word
.
for an HTML
element that is a Link
, the
method extracts the word
from the Link
.
Design the method occurs
, which determines whether the
given word
occurs in the web page or its embedded pages.