When data is collected at regular intervals, trends in the data are sometimes
easier to see by looking at a moving average. The moving average of length k
at a particular time is the average of the k most recently collected data values. So
at time t it is the average of the data reported at times t,t-1,...,t-(k-1).
The moving average is not defined at time t unless
we have data for the preceding k-1 times.
We have a sequence of data values and want to look at the moving averages of
length k of those values. Specifically, we want to know how much the largest
moving average exceeds the smallest moving average.
Create a class MovingAvg that contains a method difference that is given k and
double[] data. It returns the difference between the largest and smallest
moving average of length k in data.
|