Lab 3: Ring Buffers and Guitar Strings
Bard College – Computer Science – Data Structures

In this lab we’ll explore an array-based implementation of a ring  buffer (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 with the modifications below: http://introcs.cs.princeton.edu/java/assignments/guitar.html

Be sure to read the pages 147–151 from Chapter 1 of the Intro to CS by the authors of our textbook. 

Your ring buffer implementation should use an array (not a queue) as its underlying instance variable. The Algorithms book’s ResizingArrayQueue is a good starting place. 

Employ the testing based approach we learned last week. Use assertions to check pre- and post-conditions and in-variants whenever you can. Before worrying about GuitarString create a main method in RingBuffer that acts as a simple, straight-forward client exercising all of RingBuffer's methods. You might also add a display method to RingBuffer that prints out its contents.

Modifications:

  1. Your RingBuffer should only throw an exception if you dequeue an empty buffer, if you try and enqueue a full buffer you should just overwrite the oldest entry.
  1. Make RingBuffer generic (i.e., A RingBuffer of Double for GuitarString, but any type in general).
  RingBuffer<Double> ringbuffer = new RingBuffer<Double>(3.0);
  1. The second constructor in GuitarString is not necessary:  GuitarString(double[] init) 




Submission

Submit a zip file that expands to a folder with the following files:

cmsc201-lab3-lastname-firstname
     README.md      [names, emails, date, lab title, and collaboration statement]
     RingBuffer.java    
     GuitarString.java
     GuitarHero.java

Reminder that any outside resources in completing the lab should be included in the collaboration statements: names of drop-in tutors, links to websites or stack overflow articles, etc. 
Anything that isn’t the textbook, its website, the instructors or dedicated class tutors.
 

BONUS

  • Implement an Iterator for your RingBuffer .
 for (double d: ringbuffer){
     StdOut.println(d);
 }