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 Question

Santa Monica College Java Question

Santa Monica College Java Question

Description

PLATFORM INDEPENDENCE

  • Please see Syllabus for more information.
  • Your solution has to be platform-independent; it must run on any platforms including any online IDEs:
    • You solution should be free of any use of packages. Example, absolutely no
    • /* Java Program Example - Java Import Packages *
      package YOUR_CUSTOM_PACKAGE HERE;
    • Your solution, regardless of how many classes it has, should be in one .java file.
    • Your solution has to run on any online IDEs.
    • If your solution fails the platform-independence criteria, you will have to resubmit work subject to the late penalty.
    • The Late Work policy applies for all late submissions.
    • Your solution should be reusable, meaning it will be invoked and validated against a series of input sequentially to produce consistent outcomes like so:
    Solution sol = new Solution();
    sol.your_method1(test_input_1...);
    sol.your_method2(test_input_2 ...);
    

PROBLEM 1

( 10 points ) You learn in class as well as in reading about the Array-Based Queue Implementations, specifically the “Floating Front Design” to implement a queue using a fixed-size array. The following two scenarios from your lecture slides illustrate how this design works:

Scenario #1

floating queue.png

Scenario #2

floating queue2.png

You are responsible for implementing the areas of code indicated with YOUR CODE HERE. This Solution class implements a constructor that builds an array of a dynamic capacity at construction time. In this problem, you will be following the above mentioned Floating Front design in your textbook and lecture, and implement the FOUR (4) solution methods: add()/remove()/peek()/isEmpty(). Note these methods are named differently and both the front and rear pointers have different initialized values in this problem than what is in the lecture. DO NOT ALTER THEM in your code:

public class HW6_1 {
   public static void main(String[] args) {
      // your solution method will be tested as such, with random sequential input
      // TEST CASE #1: instantiate a queue of capacity = 1
      Solution sol = new Solution(1);
      sol.getFront(); // -1
      sol.getRear(); // -1
      sol.add(8);
      sol.getFront(); // 0
      sol.getRear(); // 0
      sol.peek(); // 8
      sol.remove(); // 8
      sol.isEmpty(); // true
      sol.getFront(); // -1, when queue is empty
      sol.getRear(); // -1, when queue is empty

      // TEST CASE #2: instantiate a queue of capacity = 3
      Solution sol = new Solution(3);
      sol.add(1);
      sol.add(2);
      sol.add(3);
      sol.getFront(); // 0
      sol.getRear(); // 2
      sol.remove(); // 1
      sol.getFront(); // 1
      sol.getRear(); // 2
      // etc
   }
}

class Solution {
   // Dynamic array size
   private int capacity;
   // Queue
   private int[] elements;
   // Dynamic queue size
   private int numElements = 0;
   // Dynamic index for the front of queue, defaulting to -1 when the queue is empty
   private int front = -1;
   // Dynamic index for the rear of queue, defaulting to -1 when the queue is empty
   private int rear = -1;

   // Constructor
   public Solution(int capacity) {
      this.capacity = capacity;
      this.elements = new int[this.capacity];
   }
   // Get the front index
   public int getFront() {
      return this.front;
   }
   // Get the rear index
   public int getRear() {
      return this.rear;
   }

   /* =====================================
   /* !!! 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

  • This problem tests your understanding of how queue works in Java by implementing it from scratch using a fixed-size array.
  • All operations called on the queue are valid. In other words, both remove() and peek() will NOT be called on an empty queue, and add() won’t be called on a queue at capacity prompting to resize. This means you won’t have to create any Exceptions to handle errors.
  • NOTE: when the queue is empty, both front and rear should have an index of -1.
  • Your solution will be tested against 9-10 test cases; -1 for each failed test.
  • Each test case includes a combination of queue operations, and getFront() and getRear() to test the correctness of your “Floating Front Design”.

SUBMISSION

  • Submit your solution in HW6_1.java.
  • There are two classes in this Java code. One of them is your HW6_1 class, and the other is the same top-level class (the one without the public access modifier) named Solution.
90/10 1 Problem
90/10 1 Problem
Criteria Ratings Pts

(1) LOGIC – correct output (-1 pt for each failed test case)

9 pts

Correct

4 pts

Effort

Showing effort though logically incorrect

0 pts

Incorrect

/ 9 pts

(1) LOGIC – incorrect function signature

0 pts

Incorrect

0 pts

Incorrect

/ 0 pts

(1) STYLING/DOCUMENTATION

1 pts

Included

0 pts

Not included

/ 1 pts

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