Question
Can someone help me with this question? /* * To change this license header, choose License Headers in Project Properties. * To change this template
Can someone help me with this question?
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package dsassignment3;
import DataStructures.EmptyCollectionException;
import DataStructures.InvalidArgumentException;
import DataStructures.LinearNode;
import java.util.ArrayList;
/**
*
* @author author
* @version Fall 2019
* @param
*/
public class WorkAheadQueue implements WorkAheadQueueADT
{
protected LinearNode front;
protected LinearNode back;
protected ArrayList> frontThreeNodes;
protected ArrayList frontThreeElements;
protected int numNodes = 0;
/**
* Default Constructor
*/
public WorkAheadQueue() {
numNodes = 0;
front = null;
back = null;
}
/**
* Removes and returns the element that is at place x in the queue.
* Precondition: x must be less than 5, x must be less than size
* Note: indexing from 0: 0 == front element, 1 == second element, etc.
*
* @param x the passed in index of the element to be removed
* @return the element removed from the queue
* @throws EmptyCollectionException if the queue is empty
* @throws InvalidArgumentException if x > 4, or x > size of collection
*
*/
@Override
public T dequeue(int x) throws EmptyCollectionException,
InvalidArgumentException {
}
/**
* Returns (without removing) the element that is at place x in the queue.
* Precondition: x must be less than 5, x must be less than size
* Note: indexing from 0: 0 == front element, 1 == second element, etc.
*
* @return the element at the front of the queue
* @throws EmptyCollectionException if the queue is empty
* @throws InvalidArgumentException if x > 4, or x > size of collection
* @param x the specified index of the element to return
*/
@Override
public T first(int x) throws EmptyCollectionException,
InvalidArgumentException {
}
/**
* Returns an ArrayList of the first three nodes in the queue
*
* @return ArrayList> array list of nodes
* @throws EmptyCollectionException if the queue is empty
*/
@Override
public ArrayList> firstThreeNodes() throws
EmptyCollectionException {
}
/**
* Returns an ArrayList of the first three elements in the queue
*
* @return ArrayList array list of elements
* @throws DataStructures.EmptyCollectionException
*/
@Override
public ArrayList firstThreeElements() throws EmptyCollectionException {
if (isEmpty()) {
throw new EmptyCollectionException ("firstThreeElements(): empty "
+ "queue");
}
frontThreeElements.clear();
LinearNode curr = front;
for (int i = 0; i < 3 && i < size(); i++) {
frontThreeElements.add(i, curr.getElement());
curr = curr.getNext();
}
return frontThreeElements;
}
/**
* Adding a specific element to the end of the queue
*
* @param element
*/
@Override
public void enqueue(T element) {
}
/**
* Removes the element at the front of queue and returns a reference to it
*
* @return
* @throws EmptyCollectionException
*/
@Override
public T dequeue() throws EmptyCollectionException {
}
/**
* Returns a reference to the element at the front of the queue
*
* @return
* @throws EmptyCollectionException
*/
@Override
public T first() throws EmptyCollectionException {
}
/**
* Returns true if the collection contains no elements
*
* @return true if the collection is empty
*/
@Override
public boolean isEmpty() {
return numNodes == 0;
}
/**
* Returns the number of elements in the collection
*
* @return the number of elements as an int
*/
@Override
public int size() {
return numNodes;
}
/**
* Returns a string representation of the collection
*
* @return a string representation of the collection
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder("");
LinearNode curr = front;
for (int i = 0; i < size(); i++) {
sb.append(curr.getElement().toString());
if (i < size() - 1) {
sb.append (", ");
}
curr = curr.getNext();
}
return sb.toString();
}
}
Step by Step Solution
3.38 Rating (120 Votes )
There are 3 Steps involved in it
Step: 1
seems like youre working on implementing a WorkAheadQueue class in Java but you have some methods le...Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started