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