need help
I need the definitions of the method copyQueue, the default constructor, and the copy constructor folr the class LinkedQueueClass.
This what i get so far
publicabstractclass DataElement
{
publicabstractboolean equals(DataElement otherElement);
//Method to determine whether two objects contain the
//same data.
//Postcondition: Returns true if this object contains the
//same data as the object otherElement;
//otherwise, it returns false.
publicabstractint compareTo(DataElement otherElement);
//Method to compare two objects.
//Postcondition: Returns a value < 0 if this object is
//less than the object otherElement;
//Returns 0 if this object is the same as
//the object otherElement.
//Returns a value > 0 if this object is
//greater than the object otherElement.
publicabstractvoid makeCopy(DataElement otherElement);
//Method to copy otherElement into this object.
//Postcondition: The data of otherElement is copied into
//this object.
publicabstract DataElement getCopy();
//Method to return a copy of this object.
//Postcondition: A copy of this object is created and
//a reference of the copy is returned.
}
publicclass IntElementextends DataElement
{
protectedint num;
//default constructor
public IntElement()
{
num = 0;
}
//constructor with a parameter
public IntElement(int x)
{
num = x;
}
//copy constructor
public IntElement(IntElement otherElement)
{
num = otherElement.num;
}
//Method to set the value of the instance variable num.
//Postcondition: num = x;
publicvoid setNum(int x)
{
num = x;
}
//Method to return the value of the instance variable num.
//Postcondition: The value of num is returned.
publicint getNum()
{
return num;
}
publicboolean equals(DataElement otherElement)
{
IntElement temp = (IntElement) otherElement;
return (num == temp.num);
}
publicint compareTo(DataElement otherElement)
{
IntElement temp = (IntElement) otherElement;
return (num - temp.num);
}
publicvoid makeCopy(DataElement otherElement)
{
IntElement temp = (IntElement) otherElement;
num = temp.num;
}
public DataElement getCopy()
{
IntElement temp =new IntElement(num);
return temp;
}
public String toString()
{
return String.valueOf(num);
}
}
publicclass QueueExceptionextends RuntimeException
{
public QueueException()
{
}
public QueueException(String msg)
{
super(msg);
}
}
publicclass QueueOverflowExceptionextends QueueException
{
public QueueOverflowException()
{
super("Queue Overflow");
}
public QueueOverflowException(String msg)
{
super(msg);
}
}
publicclass QueueUnderflowExceptionextends QueueException
{
public QueueUnderflowException()
{
super("Queue Underflow");
}
public QueueUnderflowException(String msg)
{
super(msg);
}
}
publicclass LinkedQueueClass
{
//Definition of the node
protectedclass QueueNode
{
DataElement info;
QueueNode link;
}
private QueueNode queueFront;//reference variable to the
//first element of the queue
private QueueNode queueRear;//reference variable to the
//last element of the queue
//default constructor
public LinkedQueueClass()
{
queueFront =null;
queueRear =null;
}
//copy constructor
public LinkedQueueClass(LinkedQueueClass otherQueue)
{
queueFront = otherQueue.queueFront;
queueRear = otherQueue.queueRear;
}//end copy constructor
//Method to initialize the queue to an empty state.
//Postcondition: queueFront = null; queueRear = null
publicvoid initializeQueue()
{
queueFront =null;
queueRear =null;
}
//Method to determine whether the queue is empty.
//Postcondition: Returns true if the queue is empty;
//otherwise, returns false.
publicboolean isEmptyQueue()
{
return (queueFront ==null);
}
//Method to determine whether the queue is full.
//Postcondition: Returns true if the queue is full;
//otherwise, returns false.
publicboolean isFullQueue()
{
returnfalse;
}
//Method to return the first element of the queue.
//Precondition: The queue exists and is not empty.
//Postcondition: If the queue is empty, the method throws
//QueueUnderflowException; otherwise, a
//reference to a copy of the first element
//of the queue is returned.
public DataElement front()throws QueueUnderflowException
{
if(isEmptyQueue())
thrownew QueueUnderflowException();
DataElement temp = queueFront.info.getCopy();
return temp;
}
//Method to return the last element of the queue.
//Precondition: The queue exists and is not empty.
//Postcondition: If the queue is empty, the method throws
//QueueUnderflowException; otherwise, a
//reference to a copy of the last element
//of the queue is returned.
public DataElement back()throws QueueUnderflowException
{
if(isEmptyQueue())
thrownew QueueUnderflowException();
DataElement temp = queueRear.info.getCopy();
return temp;
}
//Method to add queueElement to the queue.
//Precondition: The queue exists.
//Postcondition: The queue is changed and queueElement
//is added to the queue.
publicvoid addQueue(DataElement newElement)
{
QueueNode newNode;
newNode =new QueueNode();//create the node
newNode.info = newElement.getCopy();//store the info
newNode.link =null;//initialize the link field to null
if(queueFront ==null)//if initially the queue is empty
{
queueFront = newNode;
queueRear = newNode;
}
else//add newNode at the end
{
queueRear.link = newNode;
queueRear = queueRear.link;
}
}//end addQueue
//Method to remove the first element of the queue.
//Precondition: The queue exists and is not empty.
//Postcondition: The queue is changed and the first
//element is removed from the queue.
publicvoid deleteQueue()throws QueueUnderflowException
{
if(isEmptyQueue())
thrownew QueueUnderflowException();
queueFront = queueFront.link;//advance queueFront
if(queueFront ==null)//if after deletion the queue is
queueRear =null;//empty, set queueRear to null
}//end deleteQueue
//Method to make a copy of otherQueue.
//Postcondition: A copy of otherQueue is created and
//assigned to this queue.
publicvoid copyQueue(LinkedQueueClass otherQueue)
{
if (this != otherQueue)//avoid self-copy
copyQueue(otherQueue);
}
}
publicclass QueueProgram
{
publicstaticvoid main(String[] args)
{
LinkedQueueClass intQueue1 =new LinkedQueueClass();
LinkedQueueClass intQueue2 =new LinkedQueueClass();
LinkedQueueClass tempintQueue1 =new LinkedQueueClass();
LinkedQueueClass temmintQueue2 =new LinkedQueueClass();
intQueue1.addQueue(new IntElement(23));
intQueue1.addQueue(new IntElement(45));
intQueue1.addQueue(new IntElement(38));
intQueue2.addQueue(new IntElement(32));
intQueue2.addQueue(new IntElement(54));
intQueue2.addQueue(new IntElement(83));
System.out.print("intQueue1 elements: ");
while(!intQueue1.isEmptyQueue())
{
System.out.print(intQueue1.front() +" ");
intQueue1.deleteQueue();
}
System.out.println();
System.out.print("intQueue2 elements: ");
while(!intQueue2.isEmptyQueue())
{
System.out.print(intQueue2.front() +" ");
intQueue2.deleteQueue();
}
System.out.println();
intQueue1.copyQueue(intQueue2);
System.out.print("After copying intQueue1 elements into intQueue2, intQueue2 elements are: ");
}
}
And i'm getting this error in my output:
-jGRASP exec: java QueueProgram
intQueue1 elements: 23 45 38
intQueue2 elements: 32 54 83
java.lang.StackOverflowError
Exception in thread "main"
-jGRASP wedge2: exit code for process is 1.
-jGRASP: operation complete.

