Name ______________________________
This is part of the code to implement the model that was used with the Rainfall
program. Several sections are missing, and you should write them.
They are marked with "WRITE THIS CODE".
Write the constructor, the add, getTotal, and
getAverage methods. If there are no data points,
getAverage should return 0.0.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
// RainfallStats - Class for keeping the rainfall statistics.
public class RainfallStats {
//=========================================== instance variables
private double[] _rainMeasurements;
private int _numberOfDataPoints;
//================================================== constructor
public RainfallStats(int maxSize) {
WRITE THIS CODE
}
//========================================================= add
// Adds a data point to the rain data.
public void add(double rain) {
WRITE THIS CODE
}
//=================================================== getNumber
// Return number of data points.
public int getNumber() {
return _numberOfDataPoints;
}
//==================================================== getTotal
// Returns total rainfall.
public double getTotal() {
WRITE THIS CODE
}
//================================================== getAverage
// Returns average rainfall
public double getAverage() {
WRITE THIS CODE
}
//======================================================= clear
// Get rid of all data.
public void clear() {
_numberOfDataPoints = 0;
}
}
|