public class HallEffectBuffer {
int length;
- int index = 0;
+ int index;
double[] bufferVals;
public HallEffectBuffer(int length) {
this.length = length;
bufferVals = new double[length];
+ index = 0;
}
public void add(double val) {
for (int i = 0; i < index; i++) {
total += bufferVals[i];
}
- return total / index + 1;
+ return total / bufferVals.length;
}
}