Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Having problems with Queues, any help ad I would be great full!

  1. #1
    Member
    Join Date
    Oct 2012
    Posts
    68
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Having problems with Queues, any help ad I would be great full!

    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


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default 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

  3. #3
    Member
    Join Date
    Oct 2012
    Posts
    68
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default 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.

Similar Threads

  1. [SOLVED] Please Help (Queues)
    By husain2213 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: September 30th, 2012, 12:01 AM
  2. Great to be coding again!
    By Becca in forum Member Introductions
    Replies: 3
    Last Post: November 3rd, 2011, 06:37 AM
  3. How can I become great java ?
    By hoboy in forum Java Theory & Questions
    Replies: 4
    Last Post: February 22nd, 2011, 12:33 AM
  4. Help with queues
    By araujo3rd in forum Collections and Generics
    Replies: 2
    Last Post: March 10th, 2010, 11:20 AM
  5. Multiple Queues
    By fh84 in forum Threads
    Replies: 1
    Last Post: December 3rd, 2009, 02:28 PM