We want to be able to judge whether text is suitable for a particular age
group. We will base our judgment on the average length of a word in the text, so we
need to define what a "word" is.
We define a "word" to be a maximal sequence of letters ('A'-'Z' and/or 'a-z') within a
single line. (Maximal means that if 2 letters are adjacent within a line, they are in the same
word.) But if a line ends with a sequence of one or more letters immediately
followed by a hyphen ('-') and the next line starts with a sequence of one or more letters,
all these letters are considered to be in the same word. It is even possible that a hyphenated
word could extend across several lines (see Example 2).
Create a class Hyphenated that contains a method avgLength that is given a
String[] lines containing the lines of text and that returns the average length
of the words within the text.
|