In this lab we’ll explore an array-based implementation of a ring(or circular) buffer. Ring buffers are used for many things like producer/consumer tasks, computing moving averages, log files, and in this lab, simulating sound waves. We will follow our textbook authors’ project pretty closely: http://introcs.cs.princeton.edu/java/assignments/guitar.html
Employ the testing based approach we learned last week.
The RingBuffer class should be generic(i.e., ring buffers of Doubles, but also any type).
RingBuffer<Double> ringbuffer = new RingBuffer<Double>(3);
The RingBuffer should only throw an exception if you dequeue an empty buffer, if you try and enqueue a full bufferyou should just overwrite the oldest entry.
ringbuffer.enqueue(2)
ringbuffer.enqueue(3)
ringbuffer.enqueue(5)
ringbuffer.enqueue(7)
ringbuffer.enqueue(11)
The second constructor in GuitarString is not necessary. GuitarString(double[] init)
Extra
Implement an Iterator for your RingBuffer .
for (double d: ringbuffer){
StdOut.println(d);
}
Lab 3 Unit Test(Checklist)
Did I format the code properly(tabs & braces)?
Did I use an array in my implementation of Ring Buffer?
Is my ring buffer generic?
Did I test all the ring buffers methods?
Does it sound correct?
Did I zip & submit .java files(not .class files)?
Modifications:
RingBuffer<Double> ringbuffer = new RingBuffer<Double>(3);
ringbuffer.enqueue(2)
ringbuffer.enqueue(3)
ringbuffer.enqueue(5)
ringbuffer.enqueue(7)
ringbuffer.enqueue(11)
Extra
for (double d: ringbuffer){
StdOut.println(d);
}
Lab 3 Unit Test (Checklist)