Good day im really struggling to see what is wrong with my code any help would be awesome.
public class RingBuffer { public double[] rb; // items in the buffer private int first; // index for the next dequeue or peek private int last; // index for the next enqueue private int size; private int Capacity;// number of items in the buffer // create an empty buffer, with given max capacity public RingBuffer(int capacity) { rb = new double[capacity]; for(int k = 0;k < capacity;k++) { rb[k] = 0; } first = 0; last = 0; size = 0; Capacity = capacity; } // return number of items currently in the buffer public int size() { if((first == last) && (rb[first] ==0)) { size = 0; return size; } size = (last - first); if (size < 0) { size += Capacity; } size++; return size; } // is the buffer empty (size equals zero)? public boolean isEmpty() { if(size() ==0) return true; else return false; } // is the buffer full (size equals array capacity)? public boolean isFull() { if(size() == (Capacity)) return true; else return false; } // add item x to the end public void enqueue(double x) { if (isFull()) { throw new RuntimeException("Ring buffer overflow"); } if(isEmpty()) { rb[0] =x; } else if(last == Capacity-1) { last = 0; rb[0]=x; } else { last++; rb[last] =x; } } // delete and return item from the front public double dequeue() { if (isEmpty()) { throw new RuntimeException("Ring buffer underflow"); } double temp = rb[first]; rb[first] = 0; if (first ==( Capacity-1)) { first =0; } else { first++; } return temp; } // return (but do not delete) item from the front public double peek() { if (isEmpty()) { throw new RuntimeException("Ring buffer underflow"); } return rb[first]; } // a simple test of the constructor and methods in RingBuffer public static void main(String[] args) { int N = 10; RingBuffer buffer = new RingBuffer(N); for (int i = 1; i <= N; i++) { buffer.enqueue(i); } double t = buffer.dequeue(); buffer.enqueue(t); System.out.println("Size after wrap-around is " + buffer.size()); while (buffer.size() >= 2) { double x = buffer.dequeue(); double y = buffer.dequeue(); buffer.enqueue(x + y); } System.out.println(buffer.peek()); } //output should be Size after wrap-around is 10 // 55.0 }