[12 points] Generics A bubble tea shop serves customers fir…
[12 points] Generics A bubble tea shop serves customers first-come, first-served. Write a generic class BobaLine that models a fixed-capacity order line (a FIFO queue) using an ArrayList for the underlying representation. An enqueue is a customer joining the line; a dequeue is the barista serving the next order. Implement: The constructor, which takes the capacity as an argument. enqueue — adds the passed-in argument to the tail of the line if there is room; otherwise prints “Order line is full. Cannot add new order.” dequeue — if the line is not empty, removes the element at the head of the line and returns it; otherwise prints “Order line is empty. Cannot serve an order.” and returns null. isEmpty — returns true if the line is empty and false otherwise. As a reminder, the ArrayList class provides the following methods that you are can also use. add(E elem) — appends elem to the current end of the list remove(int index) — removes the element at the specified position and returns it size() — returns the number of elements in the list isEmpty() — returns true if the list is empty and false otherwise
Read Details