Java Reference
In-Depth Information
public class ComplexTest {
static public void main (String[] args) {
// Create two complex objects
BasicComplex ac = new BasicComplex (1,2);
BasicComplex bc = new BasicComplex (3,1);
// Add ac and bc. The ac object will hold the sum.
ac.add (bc);
...
}
}
This example illustrates some of the basic concepts of classes, how they relate
to data types, and how they could be used in mathematical applications. This
class is very limited, though. In Chapter 4 we create a complex class with more
features and take advantage of class techniques such as overloading of methods.
3.10.2 Histogram class
A histogram provides a frequency distribution for the range of values that can be
taken by a parameter of interest. These types of distributions are often made in
science and engineering studies. For example, say that an experiment measures the
voltage output of a sensor with a range of
2V.Wecreate a histogram
with, say, ten “bins” in which the first bin holds the number of hits measured
between
2V to
+
1.2, and so forth,
up to the last bin, which counts the number of times the hits were between 1.6
and 2.0.
The following BasicHist.java class provides some essential histogram
features. The class properties include instance variables for the number of bins,
an array of bins, over and underflow counts, and the range over which to bin the
values. The constructor creates an instance of the class for a given set of bins and
for a lower and upper parameter range. The three methods provide for adding an
entry to the histogram, clearing the histogram, and for obtaining the values in the
bins (including the overflow and underflow counts).
2.0 and
1.6, the second bin for between
1.6 and
/** A simple histogram class to record the frequency
*of values of a parameter of interest.
**/
public class BasicHist
{
int[] bins;
int numBins;
Search WWH ::




Custom Search