• Post Reply Bookmark Topic Watch Topic
  • New Topic

Queues  RSS feed

 
Cory Covino
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a lab that I am doing, I am having a little trouble at the start. I have already created a queue, by saying
CustomerQueue c = new CustomerQueue(). Then, I have, I have created an Id which starts at 0. I called this customerId, of course. My only problem is that I don't know how to assign the id to the queue, and then increment it. Each customer is supposed to have a unique id. Can anyone help?
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch, Cory!
I'm sure folks 'round could help you out a bit. If you were to post some relevant example code that you're working on, then it might make the conversation a bit clearer and helping you easier.
You say that each customer is supposed to have a unique id, but then you talk about assigning the id to the queue. I'm not sure I understand what you mean.
If each customer is supposed to have a unique id, then it might make sense that a customer object is defined to have an int id property.
(Now, if you're given a customer class definition, and you're not allowed to edit it, then you'll perhaps want to create something like a QueueEntry entity, each instance of which would hold a reference to a customer and have a property to maintain a customer id.)
Now, let's get a closer look at what you're trying to do...
 
Cory Covino
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the code from the queue I was talking about earlier...


Notes: I will fix the print statement problem later. Also, I haven't correctly filled out the return statements. Because I haven't learned linked lists yet, I was told by my lab instructor not to use them when making a new CustomerQueue. My instructor said to implement the queue using an array. If this is not too much trouble can someone please push me in the right direction?
[ edited to preserve formatting using the [code] and [/code] UBB tags -ds ]
[ January 11, 2004: Message edited by: Dirk Schreckmann ]
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a rather strange bit of code.Why would the constructor of a CustomerQueue create a local instance of a CustomerQueue? Also, doesn't this cause your JVM to crash as CustomerQueues would just keep creating themselves until there's no more memory available?
My instructor said to implement the queue using an array. If this is not too much trouble can someone please push me in the right direction?
OK, so perhaps a good place to start would be to add an array to your CustomerQueue. You've been pushed.
Now, which part of this assignment is causing you problems? Are you not familiar and comfortable with working with arrays? Is the concept of a queue not clear?
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!