Question
JAVA Code not compiling. Test driver error. ------------------------------------------ Exception in thread main java.lang.RuntimeException: Uncompilable source code - variable temp might not have been initialized at
JAVA Code not compiling. Test driver error.
------------------------------------------
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - variable temp might not have been initialized at LinkedQueue.toString(LinkedQueue.java:62) at LinkedQueueTest.main(LinkedQueueTest.java:7) C:\Users\USER1\AppData\Local\NetBeans\Cache\8.2\executor-snippets un.xml:53: Java returned: 1
-------------------------------------------
import support.LLNode;
public class LinkedQueue
public boolean isFull() // Returns false - a linked queue is never full. { return false; } public int size() // Returns the number of elements in this queue. { return numElements; }
@Override public String toString(){ LLNode
return result; }
public void remove(int count) throws QueueUnderflowException{
// if we have less number of items in queue, throw exception if(size() < count){ throw new QueueUnderflowException(); } // remove count number of elements from front for(int i=1; i<=count; i++) front = front.getLink(); }
public boolean swapStart(){ // if we have lesser than 2 items in queue, return false if(size() < 2){ return false; }
// swapping data of first two elements T item = front.getLink().getInfo(); // getting data of second element from front front.getLink().setInfo(front.getInfo()); // setting front's data to second element from front front.setInfo(item); // setting data to front
return true; }
public boolean swapEnds(){ // if we have lesser than 2 items in queue, return false if(size() < 2){ return false; }
LLNode
// moving temp until temp next is not rear while(temp.getLink() != rear) temp = temp.getLink();
// now temp pointing to second last element // swapping data of second last element and rear T item = temp.getInfo(); temp.setInfo(rear.getInfo()); rear.setInfo(item);
return true; } }
-----------------------
public class LLNode
-----------------------
public interface QueueInterface
T dequeue() throws QueueUnderflowException; // Throws QueueUnderflowException if this queue is empty; // otherwise, removes front element from this queue and returns it.
boolean isFull(); // Returns true if this queue is full; otherwise, returns false.
boolean isEmpty(); // Returns true if this queue is empty; otherwise, returns false. int size(); // Returns the number of elements in this queue. }
-----------------------
public class QueueUnderflowException extends RuntimeException { public QueueUnderflowException() { super(); }
public QueueUnderflowException(String message) { super(message); } } -------------------------
public class LinkedQueueTest { public static void main(String args[]) { LinkedQueue
System.out.println(s.toString()); System.out.println(s.size()); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started