Having problems with Queues, any help ad I would be great full!
I have three classes, a customer, bank and a bankQueue.
Customer:
Code :
public class Customer
{
int time;
String tags;
public Customer(int time, String tags)
{
this.time = time;
this.tags = tags;
}
}
BankQueue:
Code :
public class BankQueue
{
int front, rear;
Object[] queue;
public BankQueue(int initialCapacity)
{
if (initialCapacity < 1)
throw new IllegalArgumentException
("initialCapacity must be >= 1");
queue = new Object [initialCapacity + 1];
front = rear = 0;
}
public BankQueue()
{
this(4);
}
public void put(Object theObject)
{
if ((rear + 1) % queue.length == front)
{
Object[] newQueue = new Object[2* queue.length];
int start = (front + 1) % queue.length;
if(start < 2)
System.arraycopy(queue, start, newQueue, 0, queue.length -1);
else
{
System.arraycopy(queue, start, newQueue, 0, queue.length -start);
System.arraycopy(queue, 0, newQueue, queue.length -start, rear +1);
}
front = newQueue.length -1;
rear = queue.length -2;
queue = newQueue;
}
rear = (rear +1) % queue.length;
queue[rear] = theObject;
}
}
Now if I test this and make a BankQueue and make a Customer, add the customer to the bankQueue, then the customer will be added.
I now have a bank class:
Code :
import java.util.Queue;
public class Bank
{
BankQueue queue = new BankQueue();
public Bank()
{
}
public void Arrive(Customer customer)
{
queue.put(this);
}
}
What I am trying to do, is when a customer goes to the bank (class) I will call method arrive, then this will send the customer to my BankQueue class. At the moment it just creates a new queue.
Thank you
Re: Having problems with Queues, any help ad I would be great full!
So what should it do next?
Then ask yourself, "What steps will I take to perform that task?", and write those steps down.
Use those steps as a guide to write the code with. Ask for help if you get stuck
Re: Having problems with Queues, any help ad I would be great full!
That's what I have tried to do.
I know that in my method arrive it calls the put method from BankQueue but does not add it to that queue that I want.
steps include:
customer object created
Customer arrives (method called in bank)
pass that customers information into the put option which then adds the customer into the queue. (wrong queue)
I have a feeling that : BankQueue queue = new BankQueue();
may be wrong?
I'm not trying to create another queue.