• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Arrays and Objects for calls in a queue  RSS feed

 
Benjamin Rollins
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so am new to Java and want to understand how object arrays work . For a scenarios like this , calls are placed in a queue[0-9] and am trying to model these cases:


An instance variable which is an array of Calls to form the queue.
A second instance variable, an int which will hold the number of calls currently in the queue.
A constructor which takes the required size of the queue as its parameter and initialises the array to be of that size.
A method void add(Call call) which adds a call to the queue.
A method to get the number of calls currently in the queue.
A method boolean isEmpty() to check whether the queue is currently empty.
A new method to check whether the queue is full.




How can I model these scenarios??

 
Abigail Rosemond
Greenhorn
Posts: 13
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Benjamin Rollins wrote:so am new to Java and want to understand how object arrays work . For a scenarios like this , calls are placed in a queue[0-9] and am trying to model these cases:


An instance variable which is an array of Calls to form the queue.
A second instance variable, an int which will hold the number of calls currently in the queue.
A constructor which takes the required size of the queue as its parameter and initialises the array to be of that size.
A method void add(Call call) which adds a call to the queue.
A method to get the number of calls currently in the queue.
A method boolean isEmpty() to check whether the queue is currently empty.
A new method to check whether the queue is full.




How can I model these scenarios??



Alright here is what I came up with so far:




Give me a few minutes I may be able to make it a little better(i.e a little index checking and so forth).
 
Abigail Rosemond
Greenhorn
Posts: 13
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This is the best I could come up with. Double check that the add method doesn't throw array out of bounds(it didn't for me).
 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, Abigail.

Thanks for your contribution.  Since you're new, you may not know that in the Beginning Java forum we don't give out complete solutions.  Instead, we try to help the OP come to their own solutions through comments, questions, and short examples.

There are a number of reasons for this, but two are that we want the OP to learn instead of being spoon-fed.  The other is that this may be homework and we don't want to get the reputation of being a code mill.

Read some other threads in Beginning Java to get the idea.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!