Step 1
Develop the following interface:
Interface
Name: QueueInterface<T>
Access Modifier: public
Methods
Name: isEmpty
Access modifier: public
Parameters: none
Return type: boolean
Name: dequeue
Access modifier: public
Parameters: none
Return type: T (parameterized type)
Name: enqueue
Access modifier: public
Parameters: element (data type T, parameterized type)
Return type: void
Step 2
Develop the following class:
Class
Name: QueueNode<T>
Access Modifier: public
Instance variables
Name: info
Access modifier: private
Data type: T (parameterized type)
Name: link
Access modifier: private
Data type: QueueNode<T>
Constructors:
Name: QueueNode
Access modifier: public
Parameters: info (data type T)
Task: sets the value of this.info to the value of the info parameter
sets the value of link to null
Methods
Name: setInfo
Access modifier: public
Parameters: info (data type T)
Return type: void
Task: sets the value of this.info to the value of the info parameter
Name: getInfo
Access modifier: public
Parameters: none
Return type: T (parameterized type)
Task: returns the value of info
Name: setLink
Access modifier: public
Parameters: link (data type QueueNode<T>)
Return type: void
Task: sets the value of this.link to the value of the link parameter
Name: getLink
Access modifier: public
Parameters: none
Return type: QueueNode<T>
Task: returns the value of link
Step 3
Develop the following class:
Class
Name: ImprovedQueue<T>
Access Modifier: public
Implements: QueueInterface<T>
Instance variables
Name: front
Access modifier: private
Data type: QueueNode<T>
Constructors:
Name: ImprovedQueue
Access modifier: public
Parameters: none (default constructor)
Task: sets the value of front to null
Methods
Name: isEmpty
Access modifier: public
Parameters: none
Return type: boolean
Task: returns true if the front is equal to null; otherwise return false
Name: dequeue
Access modifier: public
Parameters: none
Return type: T (parameterized type)
Task: makes a call to the isEmpty method to see if the queue is empty and if it is return null without changing the queue; otherwise removes the front element from this queue and returns it.
Name: enqueue
Access modifier: public
Parameters: element (data type T, parameterized type)
Return type: void
Task: creates a newNode (data type QueueNode<T>) by passing the element parameter to the constructor of the QueueNode<T> class. Then it makes a call to the isEmpty method to see if the queue is empty; if it is it sets value of front to the value of newNode; otherwise it adds it to the rear of the queue. (Note: The rear of the queue is not kept explicitly by an instance variable but it can be found by finding the last node in the queue.)
Step 4
Develop a class with only a main method in it:
public class QueueDemo {
public static void main(String[] args) {
/* Inside of this main method do the following:
Create a reference to a QueueInterface<String> called myQueue and have it refer to a new object of the ImprovedQueue<String> class
Call the enqueue method on myQueue passing the String value of “A”
Call the enqueue method on myQueue passing the String value of “B”
Call the enqueue method on myQueue passing the String value of “C”
Call the enqueue method on myQueue passing the String value of “D”
Create a String variable called discard and sets it value to the value that is returned from a call to dequeue on myQueue
Set the value of discard to the value that is returned from a call to dequeue on myQueue
Create a loop that continues as long as the queue is not empty and inside this loop create a variable called front that is set each time through the loop to the value that is returned from a call to dequeue on myQueue and then the value of front is printed each time through the loop
*/
}
}
// QueueInterface.java
public interface QueueInterface<T> { public boolean isEmpty(); public T dequeue(); public void enqueue(T type); }
// QueueNode.java
public class QueueNode<T> { private T info; private QueueNode<T> link; public QueueNode(T info) { this.info = info; this.link = null; } public void setInfo(T info) { this.info = info; } public T getInfo() { return info; } public void setLink(QueueNode<T> link) { this.link = link; } public QueueNode<T> getLink() { return link; } }
// ImprovedQueue.java
public class ImprovedQueue<T> implements QueueInterface<T> { private QueueNode<T> front; public ImprovedQueue() { front = null; } @Override public boolean isEmpty() { return front == null; } @Override public T dequeue() { if (isEmpty()) { return null; } else { QueueNode<T> temp = front; front = front.getLink(); return temp.getInfo(); } } @Override public void enqueue(T type) { QueueNode<T> newNode = new QueueNode(type); if(isEmpty()) { front = newNode; } else { QueueNode<T> temp = front; while(temp.getLink() != null) { temp = temp.getLink(); } temp.setLink(newNode); } } }
// QueueDemo.java
public class QueueDemo { public static void main(String args[]) throws Exception { QueueInterface<String> myQueue = new ImprovedQueue<String>(); myQueue.enqueue("A"); myQueue.enqueue("B"); myQueue.enqueue("C"); myQueue.enqueue("D"); String discard = myQueue.dequeue(); while(!myQueue.isEmpty()) { String front = myQueue.dequeue(); System.out.println("Front = " + front); } } }
Step 1 Develop the following interface: Interface Name: QueueInterface<T> Access Modifier: public Methods Name: isEmpty Access...
Step 1 Develop the following interface: Interface Name: QueueInterface<T> Access Modifier: public Methods Name: isEmpty Access modifier: public Parameters: none Return type: boolean Name: dequeue Access modifier: public Parameters: none Return type: T (parameterized type) Name: enqueue Access modifier: public Parameters: element (data type T, parameterized type) Return type: void Step 2 Develop the following class: Class Name: QueueNode<T> Access Modifier: public Instance variables Name: info Access modifier: private Data type: T (parameterized type) Name: link Access modifier: private Data...
Step 1 Develop the following interface: Interface Name: Queue Interface<T> Access Modifier: public Methods Name: isEmpty Access modifier: public Parameters: none Return type: boolean Name: dequeue Access modifier: public Parameters: none Return type: T (parameterized type) Name: enqueue Access modifier: public Parameters: element (data type T, parameterized type) Return type: void Step 2 Develop the following class: Class Name: Queue Node<T> Access Modifier: public Instance variables Name: info Access modifier: private Data type: T (parameterized type) Name: link Access modifier:...
Step 3 Develop the following class: Class Name: ImprovedQueue<T> Access Modifier: public Implements: QueueInterface<T> Instance variables Name: front Access modifier: private Data type: QueueNode<T> Constructors: Name: ImprovedQueue Access modifier: public Parameters: none (default constructor) Task: sets the value of front to null Methods Name: isEmpty Access modifier: public Parameters: none Return type: boolean Task: returns true if the front is equal to null; otherwise return false Name: dequeue Access modifier: public Parameters: none Return type: T (parameterized type) Task: makes...
use
intellij idea
main java
Step 3 Develop the following class: Class Name: ImprovedQueue<T> Access Modifier: public Implements: QueueInterface<T> Instance variables Name: front Access modifier: private Data type: Queue Node<T> Constructors: Name: ImprovedQueue Access modifier: public Parameters: none (default constructor) Task: sets the value of front to null Methods Name: isEmpty Access modifier: public Parameters: none Return type: boolean Task: returns true if the front is equal to null; otherwise return false Name: dequeue Access modifier: public Parameters: none Return...
i was able to make sense on the others but this two i need help Name: ImprovedQueue<T> Access Modifier: public Implements: QueueInterface<T> Instance variables Name: front Access modifier: private Data type: QueueNode<T> Constructors: Name: ImprovedQueue Access modifier: public Parameters: none (default constructor) Task: sets the value of front to null Methods Name: isEmpty Access modifier: public Parameters: none Return type: boolean Task: returns true if the front is equal to null; otherwise return false Name: dequeue Access modifier: public Parameters:...
use
intellij idea
main java
wp the professor. Please make sure to only implement what is asked for. You may not add any instance variables to any class, though you may create local variables inside of a method to accomplish its task. No other methods should be created other than the ones listed here. Step 1 Develop the following interface: Interface Name: Queue Interface<T> Access Modifier: public Methods Name: isEmpty Access modifier: public Parameters: none Return type: boolean Name: dequeue...
Step 1 Develop the following interface: Interface Name: QueueInterface<T> Access Modifier: public Methods Name: isEmpty Access modifier: public Parameters: none Return type: boolean Name: dequeue Access modifier: public Parameters: none Return type: T (parameterized type) Name: enqueue Access modifier: public Parameters: element (data type T, parameterized type) Return type: void
Step 2 Develop the following class: Class Name: QueueNode<T> Access Modifier: public Instance variables Name: info Access modifier: private Data type: T (parameterized type) Name: link Access modifier: private Data type: QueueNode<T> Constructors: Name: QueueNode Access modifier: public Parameters: info (data type T) Task: sets the value of this.info to the value of the info parameter sets the value of link to null Methods Name: setInfo Access modifier: public Parameters: info (data type T) Return type: void Task: sets the...
use
intellij idea
main java
Step 2 Develop the following class: Class Name: QueueNode<T> Access Modifier: public Instance variables Name: info Access modifier: private Data type: T (parameterized type) Name: link Access modifier: private Data type: Queue Node<T> Constructors: Name: QueueNode Access modifier: public Parameters: info (data type T Task: sets the value of this.info to the value of the info parameter sets the value of link to null Methods Name: link Access modifier: private Data type: QueueNode<T> Constructors: Name:...
Step 4 Develop a class with only a main method in it: public class QueueDemo { public static void main(String[ ] args) { /* Inside of this main method do the following: Create a reference to a QueueInterface<String> called myQueue and have it refer to a new object of the ImprovedQueue<String> class Call the enqueue method on myQueue passing the String value of “A” Call the enqueue method on myQueue passing the String value of “B” Call the...