public class MovingAverage {

private int[] box;

private int times=0;

```
/** Initialize your data structure here. */
public MovingAverage(int size) {
box=new int[size];
}
public double next(int val) {
box[times%box.length]=val;
times+=1;
double total=0;
for(int i:box){
total+=i;
}
if(times>=box.length){
return total/box.length;
}
else{
return total/times;
}
}
```

}