Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using DrJava create a program that does the following: A deque (pronounced \"dec

ID: 3823908 • Letter: U

Question

Using DrJava create a program that does the following:

A deque (pronounced "deck") is a list-based collection that allows additions and removals to take place at both ends. A deque supports the operations

addFront(x)

removeFront( )

addRear(x)

removeRear( )

size( )

empty( )

Write a class that implements a deque that stores strings using a doubly-linked list that you code yourself. Demonstrate your class with a graphical user interface that allows users to manipulate the deque by typing appropriate commands in a JTextField component, and see the current state of the deque displayed in a JTextArea component. Consult the documentation for the JTextArea class for methods you can use to display each item in the deque on its own line.

This should have three separate source files. A source file for

A Deque Class

A doubly DoublyLinkedlist Class

A GUI that allows users to manipulate your deque GUIdeque Class

Thank you to anyone who takes the time to help!

Explanation / Answer

package com.java2novice.ds.queue;

import java.util.ArrayList;
import java.util.List;

public class DoubleEndedQueueImpl {

private int size;
private List<Integer> deque = new ArrayList<Integer>();

public void addFront(int item){
//add element at the beginning of the queue
System.out.println("adding at front: "+item);
deque.add(0,item);
System.out.println(deque);
}
private int size;

public void addRear(int item){
//add element at the end of the queue
System.out.println("adding at rear: "+item);
deque.add(item);
System.out.println(deque);
}

public void removeFront(){
if(deque.isEmpty()){
System.out.println("Deque underflow!! unable to remove.");
return;
}
//remove an item from the beginning of the queue
int rem = deque.remove(0);
System.out.println("removed from front: "+rem);
System.out.println(deque);
}

public void removeRear(){
if(deque.isEmpty()){
System.out.println("Deque underflow!! unable to remove.");
return;
}
//remove an item from the beginning of the queue
int rem = deque.remove(deque.size()-1);
System.out.println("removed from front: "+rem);
System.out.println(deque);
}

public static void main(String a[]){

DoubleEndedQueueImpl deq = new DoubleEndedQueueImpl();
deq.addFront(34);
deq.addRear(45);
deq.removeFront();
deq.removeFront();
deq.removeFront();
deq.addFront(21);
deq.addFront(98);
deq.addRear(5);
deq.addFront(43);
deq.removeRear();
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote