Complete the java program.
/*
Note: Do not add any additional methods, attributes.
Do not modify the given part of the program.
Run your program against the provided Homework2Driver.java for
requirements.
*/
public class QueueLinkedList<T> {
private Node front;
private Node rear;
private int size;
public QueueLinkedList() {
}
public void enqueue(T info) {
}
public T dequeue() {
}
public boolean isEmpty()
}
public int size() {
}
}
Run this program ( Homework2Driver.java ) to test.
Comment out sections that you have not finished, so it does not
interfere your troubleshooting.
For example, commenting out parts 2 and 3 while testing part 1.
public class Homework2Driver {
public static void main(String [] args) {
int score = 0;
// Part 1: Array based Queue - QueueArray.java
QueueArray myQueueArray = new QueueArray(2);
myQueueArray.dequeue();
if (myQueueArray.isEmpty() && !myQueueArray.isFull() && myQueueArray.size()
== 0)
score += 6;
myQueueArray.enqueue("Orange");
myQueueArray.enqueue("Mango");
myQueueArray.enqueue("Guava"); // Note: with Queue size 2, this won't get
into the queue.
if (myQueueArray.isFull())
score += 6;
if (myQueueArray.dequeue().equals("Orange") && myQueueArray.size() == 1
&& !myQueueArray.isEmpty())
score += 6;
if (myQueueArray.dequeue().equals("Mango") && myQueueArray.size() == 0 &&
myQueueArray.isEmpty())
score += 6;
// Part 2: Linked List based Queue - QueueLinkedList.java
QueueLinkedList myQueueList = new QueueLinkedList();
myQueueList.dequeue();
if (myQueueList.isEmpty() && myQueueList.size() == 0)
score += 6;
myQueueList.enqueue("Apple");
myQueueList.dequeue();
myQueueList.enqueue("Orange");
myQueueList.enqueue("Lemon");
if (myQueueList.dequeue().equals("Orange") && myQueueList.size() == 1 && !
myQueueList.isEmpty())
score += 6;
if (myQueueList.dequeue().equals("Lemon") && myQueueList.size() == 0 &&
myQueueList.isEmpty())
score += 6;
// Part 3: Linked List based Stack - StackLinkedList.java
StackLinkedList myStack = new StackLinkedList();
myStack.pop();
if (myStack.isEmpty() && myStack.size() == 0)
score += 6;
myStack.push("Peach");
if (!myStack.isEmpty() && myStack.size() == 1)
score += 6;
myStack.pop();
myStack.push("Pineapple");
if (myStack.pop().equals("Pineapple") && myStack.isEmpty() &&
myStack.size() == 0)
score += 6;
System.out.printf("your score is %d/60 \n", score);
}
}
======================DONE WITH PART 2 ===========
/*
Note: Do not add any additional methods, attributes.
Do not modify the given part of the program.
Run your program against the provided Homework2Driver.java for
requirements.
*/
class Node<T> {
public T element;
public Node link;
}
class QueueLinkedList<T> {
private Node front;
private Node rear;
private int size;
public QueueLinkedList() {
front = null;
rear = null;
size = 0;
}
public void enqueue(T info) {
Node n = new Node();
n.element = info;
n.link = null;
if (front == null) {
front = n;
} else {
rear.link = n;
}
rear = n;
size++;
}
public T dequeue() {
if (front == null) {
return null;
} else {
T doomed = (T) front.element;
front = front.link;
if (front == null) {
rear = null;
}
size--;
return doomed;
}
}
public boolean isEmpty() {
return size == 0;
}
public int size() {
return size;
}
}
// Run this program ( Homework2Driver.java ) to test.
//
// Comment out sections that you have not finished, so it does not
//
// interfere your troubleshooting.
//
// For example, commenting out parts 2 and 3 while testing part 1.
public class Homework2Driver {
public static void main(String[] args) {
int score = 0;
// Part 1: Array based Queue - QueueArray.java
// QueueArray myQueueArray = new QueueArray(2);
//
// myQueueArray.dequeue();
//
// if (myQueueArray.isEmpty() && !myQueueArray.isFull() && myQueueArray.size()
//
// == 0)
//
// score += 6;
//
// myQueueArray.enqueue("Orange");
//
// myQueueArray.enqueue("Mango");
//
// myQueueArray.enqueue("Guava"); // Note: with Queue size 2, this won't get
// into the queue.
//
// if (myQueueArray.isFull())
//
// score += 6;
//
// if (myQueueArray.dequeue().equals("Orange") && myQueueArray.size() == 1
//
// && !myQueueArray.isEmpty())
//
// score += 6;
//
// if (myQueueArray.dequeue().equals("Mango") && myQueueArray.size() == 0 &&
//
// myQueueArray.isEmpty())
//
// score += 6;
// Part 2: Linked List based Queue - QueueLinkedList.java
QueueLinkedList myQueueList = new QueueLinkedList();
myQueueList.dequeue();
if (myQueueList.isEmpty() && myQueueList.size() == 0)
score += 6;
myQueueList.enqueue("Apple");
myQueueList.dequeue();
myQueueList.enqueue("Orange");
myQueueList.enqueue("Lemon");
if (myQueueList.dequeue().equals("Orange") && myQueueList.size() == 1 && !
myQueueList.isEmpty())
score += 6;
if (myQueueList.dequeue().equals("Lemon") && myQueueList.size() == 0 &&
myQueueList.isEmpty())
score += 6;
// Part 3: Linked List based Stack - StackLinkedList.java
// StackLinkedList myStack = new StackLinkedList();
//
// myStack.pop();
//
// if (myStack.isEmpty() && myStack.size() == 0)
//
// score += 6;
//
// myStack.push("Peach");
//
// if (!myStack.isEmpty() && myStack.size() == 1)
//
// score += 6;
//
// myStack.pop();
//
// myStack.push("Pineapple");
//
// if (myStack.pop().equals("Pineapple") && myStack.isEmpty() &&
//
// myStack.size() == 0)
//
// score += 6;
System.out.printf("your score is %d/60 \n", score);
}
}
============================================================================
SEE OUTPUT, I have Written Node class as well as it was not provided
Thanks, PLEASE COMMENT if there is any concern.
Get Answers For Free
Most questions answered within 1 hours.