Question: The file B00000000.java contains : a class B00000000 with a main method --- which you should change to report your name you should also rename
The file B00000000.java contains : a class B00000000 with a main method --- which you should change to report your name you should also rename this to match your file name an interface Deque --- no changes should be made to this an implementation class ArrayDeque --- no changes are to be made to this a class DNode for doubly linked nodes --- no changes should be made to this an implementation class LinkedDeque --- the methods of this class are missing. The homework assignment is to complete the methods: LinkedDeque(), size(), empty(), removeFront(), removeRear(), addRear(), addFront(), toString(), main(). The only change needed in main() is to make it print your name and 8-digit ID in addition to the other tasks which are already programmed. When your homework is correctly implemented, the two deques will operate identically and produce duplicate prompts when the main program is run. In the other methods, you should supply an implementation using doubly linked nodes in such a way that a client would not see a difference between the operation of the classes ArrayDeque and Linked Deque. You must not add any additional instance variables to the class LinkedDeque. ********************************************************************/ import java.util.Scanner; public class B00000000 { public static void main(String args[]) { System.out.println("Homework B by xxxxxx "); // fill in your name here Deque q = new ArrayDeque<>(); Deque qLink = new LinkedDeque<>(); testDeque(q, qLink); // test both together } public static void testDeque(Deque q, Deque qLink) { boolean done = false; Scanner sc = new Scanner(System.in); while (!done) { try { System.out.println(" Array queue: " + q + " "); System.out.print("Linked queue: " + qLink + " "); System.out.println(" cmds are a r A R Q: >>"); String cmd = sc.next(); String entry = null; char command = cmd.charAt(0); if (command == 'a' || command == 'A') entry = sc.next(); switch (cmd.charAt(0)) { case 'Q': done = true; break; case 'a': q.addFront(entry); qLink.addFront(entry); break; case 'A': q.addRear(entry); qLink.addRear(entry); break; case 'r': q.removeFront(); qLink.removeFront(); break; case 'R': q.removeRear(); qLink.removeRear(); break; } } catch (Exception e) { System.out.println("Error " + e.toString()); } } sc.close(); } } interface Deque { public T removeFront() throws Exception; public T removeRear() throws Exception; public void addFront(T x) throws Exception; public void addRear(T x) throws Exception; public boolean empty(); public int size(); } class ArrayDeque implements Deque { private T data[]; private int front, rear, size, capacity; public ArrayDeque() { capacity = 1000; data = (T[]) new Object[capacity]; front = size = 0; rear = 1; } public ArrayDeque(int c) { capacity = c; data = (T[]) new Object[capacity]; front = size = 0; rear = 1; } public int size() { return size; } public boolean empty() { return size == 0; } public void addFront(T x) throws Exception { if (size() == capacity) throw new Exception("Deque Full"); data[front--] = x; if (front < 0) front = capacity - 1; size++; } public void addRear(T x) throws Exception { if (size() == capacity) throw new Exception("Deque Full"); data[rear++] = x; if (rear == capacity) rear = 0; size++; } public T removeFront() throws Exception { if (empty()) throw new Exception("Deque Empty"); front = front + 1; if (front == capacity) front = 0; size--; return data[front]; } public T removeRear() throws Exception { if (empty()) throw new Exception("Deque Empty"); rear = rear - 1; if (rear == -1) rear = capacity - 1; size--; return data[rear]; } // methods for testing purposes public String toString() { int i, j; String ans = ""; for (i = 0, j = front + 1; i < size; i++, j++) { if (j == capacity) j = 0; ans += data[j]; if (i < size - 1) ans += " -> "; } return ans; } } class DNode { private T data; private DNode prev, next; public DNode(T x, DNode p, DNode n) { data = x; prev = p; next = n; } public T getData() { return data; } public DNode getNext() { return next; } public DNode getPrev() { return prev; } public void setData(T x) { data = x; } public void setNext(DNode n) { next = n; } public void setPrev(DNode p) { prev = p; } } class LinkedDeque implements Deque { private DNode front, rear; private int size; // add implementations for the following methods // your code should perform in exactly the same way as the corresponding // ArrayDeque methods // you should not add any extra instance variables to the class and must // use a doubly linked list implementation. public LinkedDeque() { // add implementation } public int size() { // add implementation return 0; } public boolean empty() { // add implementation return true; } public T removeFront() throws Exception { // add implementation throw new Exception("Unimplemented"); } public T removeRear() throws Exception { // add implementation throw new Exception("Unimplemented"); } public void addRear(T x) throws Exception { // add implementation throw new Exception("Unimplemented"); } public void addFront(T x) throws Exception { // add implementation throw new Exception("Unimplemented"); } public String toString() { // add implementation return ""; } } Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
