Comeputer science .This is java problem.
PROBLEM 1
Queue (Links to an external site.) is an abstract data type(ADT) consisting of a sequence of entities with afirst-in-first-out (FIFO) (Links to an external site.) property.Queue has the following operations, in alignment with the JavaQueue interface (Links to an external site.) in the Oracle'sSDK:
- add(x): inserts the specified x element to the back of queuewithout violating capacity limitation.
- remove(): removes the head (front) of queue, returning theremoved element.
- peek(): retrieves and displays but does not remove (i.e.,read-only) the head of queue.
- isEmpty: returns whether the queue is empty or not asboolean.
Implement the above FOUR (4) operations in your Solution classas follows. You are responsible for implementing the area shown inred below. Note that you are given TWO (2) local Stacks to help youmanage the above listed queue operations.
STARTER CODE
import java.util.Stack;public class HomeworkAssignment5_1 { public static void main(String[] args) { // just like any problems, whatever you need here, etc. }}class Solution { // YOUR STACK TO USE FOR THIS PROBLEM private Stack pushStack = new Stack(); private Stack popStack = new Stack(); /* ===================================== /* !!! DO NOT MODIFY ABOVE THIS LINE!!! /* ==================================== // YOUR STYLING DOCUMENTATION HERE public void add(int x) { // YOUR CODE HERE } // YOUR STYLING DOCUMENTATION HERE public int remove() { // YOUR CODE HERE } // YOUR STYLING DOCUMENTATION HERE public int peek() { // YOUR CODE HERE } // YOUR STYLING DOCUMENTATION HERE public boolean isEmpty() { // YOUR CODE HERE }}
EXAMPLES
// TEST CASE #1Solution sol = new Solution();sol.add(8);sol.add(1); sol.peek(); // 8 (if you use System.out.println(), for example)sol.remove(); // 8sol.isEmpty(); // falsesol.remove(); // 1sol.isEmpty(); // truesol.add(2); sol.add(3); sol.peek(); // 2// TEST CASE #2// etc.
CONSTRAINTS / ASSUMPTIONS
- You must use Java Stack (Links to an external site.)(java.utils.Stack), both local pushStack and popStack instances, toimplement the solution queue for this problem; failure to do soreceives 0 logic points.
- You must use only the standard Stack methods, pop(), push(),peek(), and empty(), for this problem.
- This problem tests your understanding of how queue works inJava by implementing it from scratch using the Stack ADT youlearned.
- All operations called on the queue are valid. In other words,both remove() and peek() will NOT be called on an empty queue. Thismeans you won't have to create any Exceptions to handleerrors.
- Your solution will be tested against 9-10 test cases; -1 foreach failed test.