Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Myqueue.java // Complete the implementation of your MyArrayList class in this file import java.util.NoSuchElementException; public class MyQueue implements IQueue { // add any necessary variables

image text in transcribedimage text in transcribedimage text in transcribed

Myqueue.java

// Complete the implementation of your MyArrayList class in this file import java.util.NoSuchElementException;

public class MyQueue implements IQueue { // add any necessary variables here

@Override public void enqueue(Object item) {

}

@Override public Object dequeue() {

}

@Override public Object peek() {

}

@Override public int indexOf(Object item) {

}

@Override public int size() {

}

@Override public boolean isEmpty() {

}

// add any necessary methods or classes below

}

main.java

// you may use this file to write and run code to test your code

public class Main { public static void main(String[] args) { } }

IQueue.java

/** A queue is a first in first out (FIFO) data structure. New items are added to the end of the list. Items are removed from the front of the list. */ public interface IQueue {

/** Inserts the specified element at the end of this queue. */ public void enqueue(Object item);

/** Retrieves and removes the head of this queue. @return the first item in the queue */ public Object dequeue(); /** Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty. @return the first item in this queue or null if the queue is empty */ public Object peek();

/** searches the queue for an item. @return the zero-based index of the item in the queue; returns -1 if the item is not in the queue. */ public int indexOf(Object item);

/** A count of the number of items in the queue. @return A count of the number of items in the queue. */ public int size();

/** Tests if this queue is empty. @return true if the queue is empty */ public boolean isEmpty(); }

Required Skills Inventory - Write concrete classes that implement Java Interfaces according to specifications given in UML. - Implement the functionality of a Queue data structure. You are not allowed to use any of the standard Java collection types (like ArrayList) for this assignment. Do not import any Java standard library features from j ava. uti l, except java. util. NoSuchElementException. You may use simple arrays. You may also use any code from your MyArrayList or MyLinkedList submissions. Problem Description and Given Info For this assignment you are given the following Java source code files: - IQueue. java (This file is complete - make no changes to this file) - MyQueue.java (You must complete this file) - Main. java (You may use this file to write code to test your MyQueue) You must complete the public class named MyQueue. j ava with fields and methods as defined below. Your MyQueue. j ava will implement the IQueue interface that is provided in the IQueue. j ava file. You must implement your MyQueue class as either a linked list or an array list (refer to your MyArrayList and MyLinkedList work). Your MyQueue must not be arbitrarily limited to any fixed size at run-time. UML UML CLass Diagram: MyQueue Structure of the Fields While there are no required fields for your MyQueue class, you will need to decide what fields to implement. This decision will be largely based on your choice to implement this MyQueue as either an array list or a linked list. Structure of the Methods As described by the UML Class Diagram above, your MyQueue class must implement the following methods: - a public method named enqueue that takes an 0bject argument and returns nothing - a public method named dequeue that takes no arguments and returns an 0bject - a public method named peek that takes no arguments and returns an 0bject - a public method named index0f that takes an 0bject argument and returns an int - a public method named size that takes no arguments and returns an int - a public method named isEmpty that takes no arguments and returns an boolean MyQueue 1. This concrete class will store its elements in either an internal array list or linked list. All such implementation details must be contained in your myQueue. j ava file. You may add any additional fields, methods, and inner classes that you will need to achieve this. 2. enqueue method - Add a new item to end of the queue. For example: given the queue {1,2,3} (where the value 1 is at the front and the value 3 is currently at the back) and an instruction to enqueue ( 99), the result would be this {1,2,3,99}, with the value 99 now at the end of the queue. 3. dequeue method - Remove and return the item currently at the front of the queue. For example: given the queue {1,2,3} (where the value 1 is at the front and the value 3 is currently at the back) and an instruction to dequeue ( ), the queue would now look like this {2, 3}, and the value 1 would be returned. - Throws a NoSuchElementException if the queue is currently empty when this method is called. 4. peek method - Return (but do not remove) the item currently at the front of the queue. For example: given the queue {1,2,3} (where the value 1 is at the front and the value 3 is currently at the back) and an instruction to peek ( ), the queue would still look like this {1,2,3}, and the value 1 would be returned. - Throws a NoSuchElementException if the queue is currently empty when this method is called. 5. index0f method - Return the (zero-based) number of elements from the front or top of the collection where the specified item is first found. Returns 1 if the item is not found in the collection. For example: given the queue {1,2,3} (where the value 1 is at the front and the value 3 is currently at the back) and the instruction index f(2), the value 1 would be returned (because the value 2 was found at index 1 (1 element after the front) in the queue. For another example: given the queue {1,2,3} (where the value 1 is at the front and the value 3 is currently at the back) and the instruction index0 (99 ), the value 1 would be returned (because the value 99 is not found in the queue ). 6. size method - Returns the number of elements currently stored in the queue. 7. isEmpty method - Returns true if there are currently no items stored in this queue, otherwise returns false

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 14th East European Conference Adbis 2010 Novi Sad Serbia September 2010 Proceedings Lncs 6295

Authors: Barbara Catania ,Mirjana Ivanovic ,Bernhard Thalheim

2010th Edition

3642155758, 978-3642155758

More Books

Students also viewed these Databases questions