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

This is what i have so far. I am getting an Error in Part two .. please see belo

ID: 667142 • Letter: T

Question

This is what i have so far. I am getting an Error in Part two .. please see below for the error. I need help getting it to run.

Part 1:

import java.util.EmptyStackException;
import java.util.Scanner;
import java.util.Stack;

/**
*
* @author
*
*/
public class StackWAS {
public StackWAS(){ //constructor
  
}
static void push(Stack st, int num) { //method to push element to stack
if(!isFull(st)){
st.push(new Integer(num));
}
else{
System.out.println("Stack is full");
}
}

static void pop(Stack st) { //method to pop element from stack
st.pop();
}
static boolean isEmpty(Stack st){ //checking stack empty or not
boolean res = false;
if(st.capacity() == 0){
res = true;
}
return res;
}
static boolean isFull(Stack st){//checking stack full or not
boolean res = false;
if(st.capacity() == 20){
res = true;
}
return res;
}
static void toString (Stack st){ //string representation
System.out.println("Stack contains: "+st);
}
public static void main(String args[]) {
Stack st = new Stack();//creating object
Scanner sc = new Scanner(System.in);
while(true){
//menu dispalying
System.out.println("1. Push 2. Pop 3. isEmpty 4. isFull 5. Display 6. Exit");
int choice = sc.nextInt(); //reading choice
if(choice == 1){
System.out.println("Enter number to push");
int number = sc.nextInt();
push(st,number);
}
else if(choice == 2){
pop(st);
System.out.println("Number Popped from stack");

}
else if(choice == 3){
System.out.println("Stack Empty? " + isEmpty(st));
}
else if(choice == 4){
System.out.println("Stack Full? " + isFull(st));
}
else if(choice==5){
System.out.println("Stack contains: "+st);
}
else{ //safely exiting
break;
}
}
}
}

Part 2 I am having issues getting it to compile and run. Can you please help fix it according to what is needed from above:

My Error is: Cannot find symbol - class LinkedQueueList

import java.util.LinkedQueueList;

class QueueWAS {
private LinkedQueueList QueueList = new LinkedQueueList(); //linkedlist to store data
//methods to insert , dequeue, isEmpty
public void enqueue(int num) {
QueueList.addLast(num);
}
public E dequeue() {
return QueueList.poll();
}
public boolean isEmpty() {
return !QueueList.isEmpty();
}
}

public class GenericQueueTest {
public static void main(String[] args) {
GenericQueue empQueueList = new GenericQueue(); //queue declaring
//menu dispalying
System.out.println("1. Enqueue 2.Eequeue 3.isEmpty 4.Display 6.Exit");
int choice = sc.nextInt(); //reading choice
if(choice == 1){
System.out.println("Enter number to enqueue");
int number = sc.nextInt();
empQueueList.enqueue(number);
}
else if(choice == 2){
System.out.println("Number Dequeued from Queue: "+empQueueList.dequeue());

}
else if(choice == 3){
System.out.println("Queue Empty? " + empQueueList.isEmpty());
}
else if(choice==4){
//printing elements
while (empQueueList.isEmpty()) {
System.out.println("Elements in Queue are: "+empQueueList.dequeue());
}
}
else{ //safely exiting
break;
}
}
}

Below is Guidlines for my assignemnt to help you understand my issue.

Implement a generic stack and queue classes (StackWAS<T> and QueueWAS<T>, named to avoid confusion with the classes already defined in the JDK), using an internal array to store the elements.

Specific requirements include:

Implement a driver class for the StackWAS<String> class. There should be appropriate comments in the source code files.

Use the menu based approach you defined in Week 1 to test your stack class.

Implement a driver class for the QueueWAS<String> class. There should be appropriate comments in the source code files.

Use the menu based approach you defined in Week 1 to test your queue class.

Methods for StackWAS<T>

StackWAS (int) // constructor

void push (T)

T pop ()

T peek ()

boolean isEmpty()

boolean isFull()

String toString ()

Create a test report (stacktest.doc/docx/pdf/…) showing the correct behaviour of all the methods; include a description of the design; include screenshots of your running program.

Methods for QueueWAS<T>

QueueWAS(int) // constructor

void enqueue (T)

T dequeue ()

T peek ()

boolean isEmpty()

boolean isFull()

String toString ()

Create a test report (queuetest.doc/docx/pdf/…) showing the correct behaviour of all the methods; include a description of the design; include screenshots of your running program.

Explanation / Answer

public function LinkedQueue(list:SLinkedList = null)

Initializes a new queue. You can pass an existing singly linked list to provide queue-like access.

Parameters

list:SLinkedList (default = null) — An existing list to become the queue.

import java.util.LinkedQueueList; there is no LinkedQueueList better to import java.util.*;

First save this class in a seperate file named with StackWAS.java

import java.util.EmptyStackException;
import java.util.Scanner;
import java.util.Stack;

/**
*
* @author
*
*/
public class StackWAS {
public StackWAS(){ //constructor

}
static void push(Stack st, int num) { //method to push element to stack
if(!isFull(st)){
st.push(new Integer(num));
}
else{
System.out.println("Stack is full");
}
}

static void pop(Stack st) { //method to pop element from stack
st.pop();
}
static boolean isEmpty(Stack st){ //checking stack empty or not
boolean res = false;
if(st.capacity() == 0){
res = true;
}
return res;
}
static boolean isFull(Stack st){//checking stack full or not
boolean res = false;
if(st.capacity() == 20){
res = true;
}
return res;
}
static void toString (Stack st){ //string representation
System.out.println("Stack contains: "+st);
}
public static void main(String args[]) {
Stack st = new Stack();//creating object
Scanner sc = new Scanner(System.in);
while(true){
//menu dispalying
System.out.println("1. Push 2. Pop 3. isEmpty 4. isFull 5. Display 6. Exit");
int choice = sc.nextInt(); //reading choice
if(choice == 1){
System.out.println("Enter number to push");
int number = sc.nextInt();
push(st,number);
}
else if(choice == 2){
pop(st);
System.out.println("Number Popped from stack");

}
else if(choice == 3){
System.out.println("Stack Empty? " + isEmpty(st));
}
else if(choice == 4){
System.out.println("Stack Full? " + isFull(st));
}
else if(choice==5){
System.out.println("Stack contains: "+st);
}
else{ //safely exiting
break;
}
}
}
}
/*{
   public static void main(String[]args){
       System.out.println("Hello World!");
   }
}*/

second file named with QueueWAS.java

import java.util.*;

class QueueWAS implements Queue <QueueList> {
private LinkedQueue <QueueList> = new LinkedQueue(); //linkedlist to store data
//methods to insert , dequeue, isEmpty
public void enqueue(int num) {
QueueList.addLast(num);
}
public E dequeue() {
return QueueList.poll();
}
public boolean isEmpty() {
return !QueueList.isEmpty();
}
}

third file GenericQueueTest.java

public class GenericQueueTest {
public static void main(String[] args) {
GenericQueue empQueueList = new GenericQueue(); //queue declaring
//menu dispalying
System.out.println("1. Enqueue 2.Eequeue 3.isEmpty 4.Display 6.Exit");
int choice = sc.nextInt(); //reading choice
if(choice == 1){
System.out.println("Enter number to enqueue");
int number = sc.nextInt();
empQueueList.enqueue(number);
}
else if(choice == 2){
System.out.println("Number Dequeued from Queue: "+empQueueList.dequeue());

}
else if(choice == 3){
System.out.println("Queue Empty? " + empQueueList.isEmpty());
}
else if(choice==4){
//printing elements
while (empQueueList.isEmpty()) {
System.out.println("Elements in Queue are: "+empQueueList.dequeue());
}
}
else{ //safely exiting
break;
}
}
}

I made some changes to your program this code works perfectly

LinkedQueue () constructor
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