473,785 Members | 2,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

need help

28 New Member
I need the definitions of the method copyQueue, the default constructor, and the copy constructor folr the class LinkedQueueClas s.
This is what i get so far


Expand|Select|Wrap|Line Numbers
  1. public abstract class DataElement
  2. {
  3.     public abstract boolean equals(DataElement otherElement);
  4.       //Method to determine whether two objects contain the
  5.       //same data.
  6.       //Postcondition: Returns true if this object contains the
  7.       //               same data as the object otherElement;
  8.       //               otherwise, it returns false.
  9.  
  10.     public abstract int compareTo(DataElement otherElement);
  11.       //Method to compare two objects.
  12.       //Postcondition: Returns a value < 0 if this object is
  13.       //                    less than the object otherElement;
  14.       //               Returns 0 if this object is the same as
  15.       //                    the object otherElement.
  16.       //               Returns a value > 0 if this object is
  17.       //                  greater than the object otherElement.
  18.  
  19.     public abstract void makeCopy(DataElement otherElement);
  20.       //Method to copy otherElement into this object.
  21.       //Postcondition: The data of otherElement is copied into
  22.       //               this object.
  23.  
  24.     public abstract DataElement getCopy();
  25.       //Method to return a copy of this object.
  26.       //Postcondition: A copy of this object is created and
  27.       //               a reference of the copy is returned.
  28. }
  29.  
  30.  
  31.  
  32. public class IntElement extends DataElement
  33. {
  34.     protected int num;
  35.  
  36.       //default constructor
  37.     public IntElement()
  38.     {
  39.         num = 0;
  40.     }
  41.  
  42.       //constructor with a parameter
  43.     public IntElement(int x)
  44.     {
  45.         num = x;
  46.     }
  47.       //copy constructor
  48.     public IntElement(IntElement otherElement)
  49.     {
  50.         num = otherElement.num;
  51.     }
  52.  
  53.       //Method to set the value of the instance variable num.
  54.       //Postcondition: num = x;
  55.     public void setNum(int x)
  56.     {
  57.         num = x;
  58.     }
  59.  
  60.       //Method to return the value of the instance variable num.
  61.       //Postcondition: The value of num is returned.
  62.     public int getNum()
  63.     {
  64.         return num;
  65.     }
  66.  
  67.     public boolean equals(DataElement otherElement)
  68.     {
  69.         IntElement temp = (IntElement) otherElement;
  70.         return (num == temp.num);
  71.     }
  72.  
  73.     public int compareTo(DataElement otherElement)
  74.     {
  75.         IntElement temp = (IntElement) otherElement;
  76.         return (num - temp.num);
  77.     }
  78.  
  79.     public void makeCopy(DataElement otherElement)
  80.     {
  81.         IntElement temp = (IntElement) otherElement;
  82.         num = temp.num;
  83.     }
  84.  
  85.     public DataElement getCopy()
  86.     {
  87.         IntElement temp = new IntElement(num);
  88.         return temp;
  89.     }
  90.  
  91.     public String toString()
  92.     {
  93.         return String.valueOf(num);
  94.     }
  95. }
  96.  
  97.  
  98.  
  99. public class QueueException extends RuntimeException
  100. {
  101.     public QueueException()
  102.     {
  103.     }
  104.  
  105.     public QueueException(String msg)
  106.     {
  107.         super(msg);
  108.     }
  109. }
  110.  
  111.  
  112.  
  113. public class QueueOverflowException extends QueueException
  114. {
  115.     public QueueOverflowException()
  116.     {
  117.          super("Queue Overflow");
  118.     }
  119.  
  120.     public QueueOverflowException(String msg)
  121.     {
  122.         super(msg);
  123.     }
  124. }
  125.  
  126.  
  127.  
  128. public class QueueUnderflowException extends QueueException
  129. {
  130.     public QueueUnderflowException()
  131.     {
  132.          super("Queue Underflow");
  133.     }
  134.  
  135.     public QueueUnderflowException(String msg)
  136.     {
  137.         super(msg);
  138.     }
  139. }
  140.  
  141.  
  142.  
  143. public class LinkedQueueClass
  144. {
  145.           //Definition of the node
  146.     protected class QueueNode
  147.     {
  148.         DataElement info;
  149.         QueueNode link;
  150.     }
  151.  
  152.     private QueueNode queueFront; //reference variable to the
  153.                                   //first element of the queue
  154.     private QueueNode queueRear;  //reference variable to the
  155.                                   //last element of the queue
  156.         //default constructor
  157.     public LinkedQueueClass()
  158.     {
  159.         queueFront = null;
  160.         queueRear  = null;
  161.     }
  162.  
  163.  
  164.         //copy constructor
  165.     public LinkedQueueClass(LinkedQueueClass otherQueue)
  166.     {
  167.         queueFront = otherQueue.queueFront;
  168.         queueRear  = otherQueue.queueRear;
  169.     }//end copy constructor
  170.  
  171.         //Method to initialize the queue to an empty state.
  172.         //Postcondition: queueFront = null; queueRear = null
  173.      public void initializeQueue()
  174.      {
  175.           queueFront = null;
  176.           queueRear = null;
  177.      }
  178.  
  179.         //Method to determine whether the queue is empty.
  180.         //Postcondition: Returns true if the queue is empty;
  181.         //               otherwise, returns false.
  182.      public boolean isEmptyQueue()
  183.      {
  184.           return (queueFront == null);
  185.      }
  186.  
  187.  
  188.         //Method to determine whether the queue is full.
  189.         //Postcondition: Returns true if the queue is full;
  190.         //               otherwise, returns false.
  191.      public boolean isFullQueue()
  192.      {
  193.           return false;
  194.      }
  195.  
  196.         //Method to return the first element of the queue.
  197.         //Precondition: The queue exists and is not empty.
  198.         //Postcondition: If the queue is empty, the method throws
  199.         //               QueueUnderflowException; otherwise, a
  200.         //               reference to a copy of the first element
  201.         //               of the queue is returned.
  202.      public DataElement front() throws QueueUnderflowException
  203.      {
  204.           if(isEmptyQueue())
  205.              throw new QueueUnderflowException();
  206.  
  207.           DataElement temp = queueFront.info.getCopy();
  208.           return temp;
  209.      }
  210.  
  211.         //Method to return the last element of the queue.
  212.         //Precondition: The queue exists and is not empty.
  213.         //Postcondition: If the queue is empty, the method throws
  214.         //               QueueUnderflowException; otherwise, a
  215.         //               reference to a copy of the last element
  216.         //               of the queue is returned.
  217.      public DataElement back() throws QueueUnderflowException
  218.      {
  219.           if(isEmptyQueue())
  220.              throw new QueueUnderflowException();
  221.  
  222.           DataElement temp = queueRear.info.getCopy();
  223.           return temp;
  224.      }
  225.  
  226.  
  227.         //Method to add queueElement to the queue.
  228.         //Precondition: The queue exists.
  229.         //Postcondition: The queue is changed and queueElement
  230.         //               is added to the queue.
  231.      public void addQueue(DataElement newElement)
  232.      {
  233.           QueueNode newNode;
  234.  
  235.           newNode = new QueueNode();  //create the node
  236.  
  237.           newNode.info = newElement.getCopy();  //store the info
  238.           newNode.link = null;   //initialize the link field to null
  239.  
  240.           if(queueFront == null) //if initially the queue is empty
  241.           {
  242.              queueFront = newNode;
  243.              queueRear = newNode;
  244.           }
  245.           else   //add newNode at the end
  246.           {
  247.              queueRear.link = newNode;
  248.              queueRear = queueRear.link;
  249.           }
  250.      }//end addQueue
  251.  
  252.  
  253.         //Method to remove the first element of the queue.
  254.         //Precondition: The queue exists and is not empty.
  255.         //Postcondition: The queue is changed and the first
  256.         //               element is removed from the queue.
  257.      public void deleteQueue() throws QueueUnderflowException
  258.      {
  259.           if(isEmptyQueue())
  260.              throw new QueueUnderflowException();
  261.  
  262.           queueFront = queueFront.link; //advance queueFront
  263.  
  264.           if(queueFront == null)  //if after deletion the queue is
  265.              queueRear = null;  //empty, set queueRear to null
  266.      } //end deleteQueue
  267.  
  268.  
  269.         //Method to make a copy of otherQueue.
  270.         //Postcondition: A copy of otherQueue is created and
  271.         //               assigned to this queue.
  272.     public void copyQueue(LinkedQueueClass otherQueue)
  273.     {
  274.       if (this != otherQueue)  //avoid self-copy
  275.           copyQueue(otherQueue);
  276.     }
  277. }
  278.  
  279.  
  280.  
  281. public class QueueProgram
  282. {
  283.     public static void main(String[] args)
  284.     {
  285.         LinkedQueueClass intQueue1 = new LinkedQueueClass();
  286.         LinkedQueueClass intQueue2 = new LinkedQueueClass();
  287.         LinkedQueueClass tempintQueue1 = new LinkedQueueClass();
  288.         LinkedQueueClass temmintQueue2 = new LinkedQueueClass();
  289.  
  290.  
  291.         intQueue1.addQueue(new IntElement(23));
  292.         intQueue1.addQueue(new IntElement(45));
  293.         intQueue1.addQueue(new IntElement(38));
  294.  
  295.         intQueue2.addQueue(new IntElement(32));
  296.         intQueue2.addQueue(new IntElement(54));
  297.         intQueue2.addQueue(new IntElement(83));
  298.  
  299.  
  300.         System.out.print("intQueue1 elements: ");
  301.  
  302.         while(!intQueue1.isEmptyQueue())
  303.         {
  304.             System.out.print(intQueue1.front() + " ");
  305.             intQueue1.deleteQueue();
  306.         }
  307.  
  308.         System.out.println();
  309.  
  310.         System.out.print("intQueue2 elements: ");
  311.  
  312.         while(!intQueue2.isEmptyQueue())
  313.         {
  314.             System.out.print(intQueue2.front() + " ");
  315.             intQueue2.deleteQueue();
  316.         }
  317.  
  318.         System.out.println();
  319.  
  320.         intQueue1.copyQueue(intQueue2);
  321.         System.out.print("After copying intQueue1 elements into intQueue2, intQueue2 elements are: ");
  322.  
  323.  
  324.  
  325.     }
  326. }
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.Stack OverflowError
Exception in thread "main"
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
Nov 14 '06
10 2090
satan
28 New Member
How does the problem want you to write the copyQueue method then?There are several ways of doing it.
This is the heading for the method copyQueue

Expand|Select|Wrap|Line Numbers
  1. /Method to make a copy of otherQueue.
  2.         //Postcondition: A copy of otherQueue is created and
  3.         //               assigned to this queue.
  4.     public void copyQueue(LinkedQueueClass otherQueue)
Nov 20 '06 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

6
6328
by: mike | last post by:
Hello, After trying to validate this page for a couple of days now I was wondering if someone might be able to help me out. Below is a list of snippets where I am having the errors. 1. Line 334, column 13: there is no attribute "SRC" <bgsound src="C:\My Documents\zingwent.mids"> You have used the attribute named above in your document, but the document type you are using does not support that attribute for this element. This error is...
5
2196
by: John Flynn | last post by:
hi all i'm going to be quick i have an assignment due which i have no idea how to do. i work full time so i dont have the time to learn it and its due date has crept up on me .. As follows: Objectives The purpose of this assignment is to have you practice the design of object-oriented classes, including one or more of the following concepts
0
1840
by: xunling | last post by:
i have a question about answering ..... this topic is "need help" what do i have to write at te topic line, !after i have klicked the "answer message" button ive tried many possibilities, all dont work "Re:" need help "Re:need help"
9
2938
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with a device. The definition of the table is as follows: CREATE TABLE devicedata ( device_id int NOT NULL REFERENCES devices(id), -- id in the device
7
3306
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte buffer into the character pointer. The code looks like the following: #include <stdio.h> #include <stdlib.h> #include "stdafx.h" BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call,
15
4644
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to communicate with a MySQL database table on a web server, from inside of my company's Access-VBA application. I know VBA pretty well but have never before needed to do this HTTP/XML/MySQL type functions.
16
2540
by: pamelafluente | last post by:
I am still working with no success on that client/server problem. I need your help. I will submit simplified versions of my problem so we can see clearly what is going on. My model: A client uses IE to talk with a server. The user on the client (IE) sees an ASP net page containing a TextBox. He can write some text in this text box and push a submit button.
8
2750
by: skumar434 | last post by:
i need to store the data from a data base in to structure .............the problem is like this ....suppose there is a data base which stores the sequence no and item type etc ...but i need only the sequence nos and it should be such that i can access it through the structure .plz help me .
0
3963
by: U S Contractors Offering Service A Non-profit | last post by:
Brilliant technology helping those most in need Inbox Reply U S Contractors Offering Service A Non-profit show details 10:37 pm (1 hour ago) Brilliant technology helping those most in need Inbox Reply from Craig Somerford <uscos@2barter.net> hide details 10:25 pm (3 minutes ago)
20
4286
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site is structured as an upside-down tree, and (if I remember correctly) never more than 4 levels. The site basically grew (like the creeping black blob) ... all the pages were created in Notepad over the last
0
9646
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10346
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10096
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9956
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8982
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5514
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.