Java Reference
In-Depth Information
// Negative bin values gives the underflows
System.out.println (" Underflows =" + bh.getValue
(-1));
// Bin values above the range give the overflows.
System.out.println ("Overflows ="+ bh.getValue (10));
}
}
When we run the above applet, an output similar to the following is produced.
We see that the distribution does in fact roughly follow the general shape of a
Gaussian centered in the middle bins.
Bin 0 = 3
Bin 1 = 8
Bin 2 = 12
Bin 3 = 14
Bin 4 = 15
Bin 5 = 17
Bin 6 = 9
Bin 7 = 9
Bin 8 = 7
Bin 9 = 3
Underflows = 1
Overflows = 2
In the coming chapters and in the Web Course we develop a more capable his-
togram class and use it for many examples.
3.10.3 Object-oriented vs. procedural programming
If your program had 20 parameters to examine, you can simply create 20 instances
of BasicHist , each with its own number of bins and range limits relevant to
that parameter. If at some later point, we add new methods and instance variables
to the BasicHist ,you don't need to modify the code in your program as long
as the changes are internal to BasicHist and don't affect the parameter lists in
the methods that you invoke.
If you think about how to do histogramming in a traditional procedural code
approach, you should start to appreciate the elegance of the object-oriented
approach. In a procedural program, you would need to create arrays to hold the
histogram values. You might create a number of 1D histograms or, for the case of
Search WWH ::




Custom Search