Histogram Project

Class Histogram

java.lang.Object
  |
  +--Histogram

public class Histogram
extends java.lang.Object

Environment-Based Applications:
The Histogram class constructs a histogram of a set of integer values.

Version:
1 December 2002

Constructor Summary
Histogram(java.lang.String title, int[] values, int maxValue)
          Constructs a histogram for the specified values and displays it.
Histogram(java.lang.String title, int numValues, int maxValue)
          Constructs a histogram for a certain number of values.
 
Method Summary
 void display()
          Displays the histogram.
 void labelColumns()
          Label the "x-axis" of the histogram with the values represented by each column.
 void labelColumns(int periodicity)
          Label the "x-axis" of the histogram with the values represented by the columns; which columns are labeled depends on the periodicity.
 void plot(int row, int value)
          Plots a row in the histogram; assumes that the histogram was created with the first constructor.
 void plot(java.lang.String label, int row, int value)
          Plots a labeled row in the histogram; assumes that the histogram was created with the first constructor.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Histogram

public Histogram(java.lang.String title,
                 int numValues,
                 int maxValue)
Constructs a histogram for a certain number of values. (Precondition: numValues < 20.)
Parameters:
title - title for top of window displaying histogram
numValues - the number of values to plot
maxValue - the maximum value that could be plotted; the histogram is scaled so that a full row represents this value

Histogram

public Histogram(java.lang.String title,
                 int[] values,
                 int maxValue)
Constructs a histogram for the specified values and displays it. (Precondition: values.length < 20 and every value in values is less than or equal to maxValue.)
Parameters:
title - title for top of window displaying histogram
values - the list of values to plot
maxValue - the maximum value that could be plotted; the histogram is scaled so that a full row represents this value
Method Detail

plot

public void plot(int row,
                 int value)
Plots a row in the histogram; assumes that the histogram was created with the first constructor. (Precondition: 0 <= row < numValues and 0 <= value <= maxValue, where numValues and maxValue are the values specified when the histogram was constructed.)
Parameters:
row - the row in which a value is to be plotted (0 represents the first row, 1 represents the second row, and so forth)
value - the value to be plotted

plot

public void plot(java.lang.String label,
                 int row,
                 int value)
Plots a labeled row in the histogram; assumes that the histogram was created with the first constructor. (Precondition: 0 <= row < numValues and 0 <= value <= maxValue, where numValues and maxValue are the values specified when the histogram was constructed. Also, label is a short enough string to be displayed in a single cell in the histogram grid.)
Parameters:
label - the label for the row
row - the row in which a value is to be plotted
value - the value to be plotted

labelColumns

public void labelColumns()
Label the "x-axis" of the histogram with the values represented by each column.

labelColumns

public void labelColumns(int periodicity)
Label the "x-axis" of the histogram with the values represented by the columns; which columns are labeled depends on the periodicity. If the periodicity is 1 then every column is labeled; if the periodicity is 2 then every other column is labeled; it it's 3 then every third column is labeled; etc. The first and last columns, however, are always labeled, regardless of the periodicity.

display

public void display()
Displays the histogram.

Histogram Project

Copyright© 2003 Alyce Brady