Java Version of 2000 A1 Free Response

Consider a class Histogram for printing histograms, or bar graphs, representing data stored in an array of int values.

For example if array data represents [3,5,9,10,12,11,9,4], then the code below prints the histogram that follows the code.

    Histogram histo = new Histogram();
    histo.print(data,20,"x");          // longest bar has 20 "x"'s

The code above prints this histogram.

   xxxxx
   xxxxxxxx
   xxxxxxxxxxxxxxx
   xxxxxxxxxxxxxxxx
   xxxxxxxxxxxxxxxxxxxx
   xxxxxxxxxxxxxxxxxx
   xxxxxxxxxxxxxxx
   xxxxxx

The class Histogram is shown below.



Owen L. Astrachan
Last modified: Wed Jul 10 10:03:25 EDT 2002