Question: 8.7. Re-implement the BoundedQueue class as a subtype of the Queue interface type in the standard library ch08/queue/BoundedQueue.java 1 import java.util.*; 2 3 /** 4
8.7. Re-implement the BoundedQueue class as a subtype of the Queue interface type in the standard library
ch08/queue/BoundedQueue.java 1 import java.util.*; 2 3 /** 4 A first-in, first-out bounded collection of objects. 5 */ 6 public class BoundedQueue
Below are files that are required for the question
JunitTestBoundedQueue.java
import static org.junit.Assert.*;
import org.junit.Test;
public class JunitTestBoundedQueue {
BoundedQueue
BoundedQueue
@Test
public void testAddSizePeek() {
iQueue.add(10);
sQueue.add("aa");
assertTrue(iQueue.size() == 1);
assertTrue(sQueue.size() == 1);
assertTrue(iQueue.peek() == 10);
assertTrue(sQueue.peek().equals("aa"));
}
@Test
public void testRemove() {
iQueue.add(10);
iQueue.add(20);
sQueue.add("aa");
assertTrue(iQueue.size() == 2);
assertTrue(sQueue.size() == 1);
assertTrue(iQueue.peek() == 10);
assertTrue(sQueue.peek().equals("aa"));
assertTrue(iQueue.remove() == 10);
assertTrue(iQueue.peek() == 20);
assertTrue(iQueue.size() == 1);
}
}
TestBoundedQueue.java
import java.util.Iterator;
public class TestBoundedQueue {
static BoundedQueue
static BoundedQueue
public static void main(String[] args) {
iQueue.add(10);
iQueue.add(20);
Iterator
while(iteratorI.hasNext()) {
System.out.print(iteratorI.next() + " ");
}
System.out.println();
sQueue.add("aa");
sQueue.add("bb");
sQueue.add("cc");
Iterator
while(iteratorS.hasNext()) {
System.out.print(iteratorS.next() + " ");
}
System.out.println();
sQueue.remove();
iteratorS = sQueue.iterator();
while(iteratorS.hasNext()) {
System.out.print(iteratorS.next() + " ");
}
System.out.println();
}
}
This question is from Ch.8 of A Crash Course in Java
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
