Given a sequence of values, we want to display a histogram of vertical
bars with a title at the bottom of each bar. Each value will be an integer,
and the corresponding bar will consist of that many 'X' characters. For
example,
X
X
X X
X X X X X
EAST NORTH SOUTH WEST INTERNATIONAL
We require that the bars be centered over their titles, using the more leftward of
the two middle positions for a title whose length is even. We require that
there must be at least one space between adjacent titles, and
that the number of spaces between adjacent bars be constant.
In the example above, there are 9 spaces between adjacent bars.
Create a class Histogram that contains a method draw that is given a String[]
title and a int[] value. It returns a String[] in which each element is the next
row of the histogram to be printed, starting with the top row and ending with the row that
contains the titles.
The histogram must preserve the order given in title and value. The spacing
between bars should be as small as possible.
Each element of the return
should be as short as possible; this implies that the final element of the
return will have no leading spaces,
and that no element of the return will have trailing spaces.
|