Need help with your Discussion

Get a timely done, PLAGIARISM-FREE paper
from our highly-qualified writers!

glass
pen
clip
papers
heaphones

Santa Monica College Java Worksheet

Santa Monica College Java Worksheet

Santa Monica College Java Worksheet

Description

( 10 points ) Queue (Links to an external site.) is an abstract data type (ADT) consisting of a sequence of entities with a first-in-first-out (FIFO) (Links to an external site.) property. Queue has the following operations, in alignment with the Java Queue interface (Links to an external site.) in the Oracle’s SDK:

  • add(x): inserts the specified x element to the back of queue without violating capacity limitation.
  • remove(): removes the head (front) of queue, returning the removed 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 as boolean.

Implement the above FOUR (4) operations in your Solution class as follows. You are responsible for implementing the area shown in red below. Note that you are given TWO (2) local Stacks to help you manage the above listed queue operation

STARTER CODE

import java.util.Stack;

public class HW5_1 {
  public static void main(String[] args) {
     // your solution will be tested w/ random add()'s and remove()'s.
     // Observers like peek(), isEmpty() will be used along the way to validate.
     Solution sol = new Solution();
     sol.add(8);
     sol.add(1);
     sol.peek();    // 8, if you use System.out.print()
     sol.remove();  // 8
     sol.isEmpty(); // false
     sol.add(2);
     sol.add(3);
     sol.peek();    // 1    
     // etc
  }
}
class Solution {
   // PLEASE USE THESE GLOBAL STACKS FOR THIS PROBLEM
   private Stack<Integer> pushStack = new Stack<Integer>();
   private Stack<Integer> popStack = new Stack<Integer>();
   /*
    * ====================================
    * !!! DO NOT MODIFY ABOVE THIS LINE!!!
    * ====================================
    */

   /**
* PURPOSE:
* PARAMETERS:
* RETURN VALUES:
    */
   public void add(int x) {
       // YOUR CODE HERE
   }

   /**
* PURPOSE:
* PARAMETERS:
* RETURN VALUES:
    */
   public int remove() {
       // YOUR CODE HERE
   }

   /**
* PURPOSE:
* PARAMETERS:
* RETURN VALUES:
    */
   public int peek() {
       // YOUR CODE HERE
   }

   /**
* PURPOSE:
* PARAMETERS:
* RETURN VALUES:
    */
   public boolean isEmpty() {
       // YOUR CODE HERE
   }
}

CONSTRAINTS / ASSUMPTIONS

  • You MUST use Java Stack (Links to an external site.) (java.utils.Stack), both local pushStack and popStack instances, to implement the solution queue for this problem; solution without the use of java.utils.Stack receives 0 logic points.
  • You will used the provided global stacks in your Solution class for this problem.
  • 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 in Java by implementing it from scratch using the Stack ADT you learned.
  • All operations called on the queue are valid. This means both remove() and peek() will NOT be called on an empty queue. You won’t have to create custom Exceptions to handle errors.

Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."

Order Solution Now

Our Service Charter


1. Professional & Expert Writers: Eminence Papers only hires the best. Our writers are specially selected and recruited, after which they undergo further training to perfect their skills for specialization purposes. Moreover, our writers are holders of masters and Ph.D. degrees. They have impressive academic records, besides being native English speakers.

2. Top Quality Papers: Our customers are always guaranteed of papers that exceed their expectations. All our writers have +5 years of experience. This implies that all papers are written by individuals who are experts in their fields. In addition, the quality team reviews all the papers before sending them to the customers.

3. Plagiarism-Free Papers: All papers provided by Eminence Papers are written from scratch. Appropriate referencing and citation of key information are followed. Plagiarism checkers are used by the Quality assurance team and our editors just to double-check that there are no instances of plagiarism.

4. Timely Delivery: Time wasted is equivalent to a failed dedication and commitment. Eminence Papers are known for the timely delivery of any pending customer orders. Customers are well informed of the progress of their papers to ensure they keep track of what the writer is providing before the final draft is sent for grading.

5. Affordable Prices: Our prices are fairly structured to fit in all groups. Any customer willing to place their assignments with us can do so at very affordable prices. In addition, our customers enjoy regular discounts and bonuses.

6. 24/7 Customer Support: At Eminence Papers, we have put in place a team of experts who answer all customer inquiries promptly. The best part is the ever-availability of the team. Customers can make inquiries anytime.

We Can Write It for You! Enjoy 20% OFF on This Order. Use Code SAVE20

Stuck with your Assignment?

Enjoy 20% OFF Today
Use code SAVE20