I have three classes, a customer, bank and a bankQueue.
Customer:
public class Customer { int time; String tags; public Customer(int time, String tags) { this.time = time; this.tags = tags; } }
BankQueue:
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:
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