Question
Implement a value-pass to the following: import java.util.ArrayList; public class BufferTest implements Buffering { private static final int EXAMPLE = 5; public ArrayList EXAMPLE1; private
Implement a value-pass to the following:
import java.util.ArrayList;
public class BufferTest implements Buffering
private static final int EXAMPLE = 5;
public ArrayList
private int in, out, count;
public BufferTest() {
count = 0;
in = 0;
out = 0;
EXAMPLE1 = new ArrayList<>(EXAMPLE);
}
public void insert(String item) {
while (count == EXAMPLE)
; // do nothing -- no free space
// add an element to the buffer
EXAMPLE1.add(item);
in = (in + 1) % EXAMPLE;
++count;
}
// consumers call this method
public String remove() {
String item;
while (count == 0)
; // do nothing - nothing to consume
// removes from the buffer
item = EXAMPLE1.get(out);
out = (out + 1) % EXAMPLE;
--count;
return item;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started