publicclassMovingAverage {Queue<Integer> queue;int size;int sum; /** Initialize your data structure here. */publicMovingAverage(int size) { queue =newLinkedList<Integer>();this.size= size; sum =0; }publicdoublenext(int val) {if (queue.size() < size) {queue.offer(val); sum += val; } else {int tmp =queue.poll(); sum -= tmp;queue.add(val); sum += val; }return (double) sum /queue.size(); }}/** * Your MovingAverage object will be instantiated and called as such: * MovingAverage obj = new MovingAverage(size); * double param_1 = obj.next(val); */