Question

i was able to make sense on the others but this two i need help Name:...

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: 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.)

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

*/  

}

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// 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);
        }
    }
}
Add a comment
Know the answer?
Add Answer to:
i was able to make sense on the others but this two i need help Name:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 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: 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...

  • use intellij idea main java wp the professor. Please make sure to only implement what is...

    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 3 Develop the following class: Class Name: ImprovedQueue<T> Access Modifier: public Implements: QueueInterface<T> Instance variables...

    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...

  • Step 1 Develop the following interface: Interface Name: Queue Interface<T> Access Modifier: public Methods Name: isEmpty...

    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:...

  • use intellij idea main java Step 3 Develop the following class: Class Name: ImprovedQueue<T> Access Modifier:...

    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...

  • Step 4 Develop a class with only a main method in it: public class QueueDemo {...

    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...

  • use intellij idea main java Step 4 Develop a class with only a main method in...

    use intellij idea main java Step 4 Develop a class with only a main method in it: public class QueueDemot public static void main(String[] args) { Inside of this main method do the following: Create a reference to a Queue Interface<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...

  • what is wrong with my code. what should I do with this kind of error 61...

    what is wrong with my code. what should I do with this kind of error 61 QueueDemo java - Files - RaProjects/one- A Queue Demoava Queueinterface Java inport java.util.LinkedList; import java.util.Queue public class QueueDemo public static void main(String[] args) { 10 11 12 13 Queue String myQueue new LinkedlistString();//Create a reference to a queue Interface myqueue.add("A");//Call the enqueue method on myQueue passing the string value of "A" myQueue.add("B");//call the enqueue method on nyQueue passing the String value of "3" myQueue.add("C");//Call...

  • 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

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT