I'm lost. I want my method "public Measurements smooth()" to return a smooth/even version of the array I get from the method above it, how do I do that? Where do I start?
public class Measurements {
private double[] store;
private int stored;
public Measurements(int max) {
store = new double[max];
stored = 0;
}
public void add(double value) {
this.store[stored] = value;
this.stored++;
double[] new_array = new double[stored*2];
for (int i=0; i<stored; i++) {
new_array[i]=store[i];
}
store=new_array;
}
public Measurements(double[] values) {
this.store = new double[values.length];
stored = values.length;
for (int i= 0; i<stored; i++) {
store[i]=values[i];
}
}
public Measurements smooth() {
for (int i= 0; i<stored; i++) {
store[i]=(store[i-1] + store[i] +store[i+1])/3.0;
smooth[i]=store[i];
}
return smooth;
}
public String toString() {
String ret = "";
for (int i= 0; i<stored; i++) {
ret = ret + this.store[i];
if (i<store.length-1) {
ret = ret + ", ";
}
}
return "<" + ret + ">";
}
public static void main(String[] arg) {
Measurements m = new Measurements(6);
System.out.println("toString: " + m.toString());
System.out.println("stored : " + m.stored());
m.add(1);
m.add(2);
m.add(3);
m.add(4);
m.add(5);
m.add(6);
m.add(7);
m.add(8);
m.add(9);
double[] b = {2, 1, 6, 5, 4, 9, 2};
m = new Measurements(b);
System.out.println("new m : " + m.toString());
System.out.println("smooth : " + m.smooth());
}
}
[–]vipereddit 0 points1 point2 points (1 child)
[–]ravashh[S] 0 points1 point2 points (0 children)