Welcome to Dream.In.Code
Become a Java Expert!

Join 150,425 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,079 people online right now. Registration is fast and FREE... Join Now!




Fix it again...

 
Reply to this topicStart new topic

Fix it again...

ioncrew
15 Mar, 2008 - 09:03 AM
Post #1

New D.I.C Head
*

Joined: 5 Mar, 2008
Posts: 9

CODE


public class CircularQueue {

    /** Array of references to the objects being queued. */
    protected Object queue[] = null;

    /** The array index for the next object to be stored in the queue. */
    protected int sIndex;

    /** The array index for the next object to be removed from the queue. */
    protected int rIndex;

    /** Number of objects currently stored in the queue. */
    protected int count;

    /** The number of objects in the array (Queue size + 1). */
    protected int qSize;

    /**
     * Creates a circular queue of size s (s objects).
     *
     * @param s The maximum number of elements to be queued.
     */
    public CircularQueue(int s) {
        qSize = s + 1;
        sIndex = 0;
        rIndex = qSize;
        count = 0;
        queue = new Object[qSize];
    }

    /**
     * Stores an object in the queue.
     *
     * @param x The object to be stored in the queue.
     * @return true if successful, false otherwise.
     * @exception ArrayIndexOutOfBoundsException
     */
    public boolean put(Object x) throws ArrayIndexOutOfBoundsException {

        if ((sIndex + 1 == rIndex) ||
            ((sIndex + 1 == qSize ) && (rIndex == 0))) {
            // queue is full
            return false;
        } else {
            // insert object into queue.
            queue[sIndex++] = x;
            count++;
            if (sIndex == qSize) {
                // loop back
                sIndex = 0;
            }
        }
        return true;
    }

    /**
     * Removes an object from the queue.
     *
     * @return a reference to the object being retrieved.
     * @exception ArrayIndexOutOfBoundsException
     */
    public Object get() throws ArrayIndexOutOfBoundsException {

        if (rIndex == qSize) {
            // loop back
            rIndex = 0;
        }
        if (rIndex == sIndex) {
            // queue is empty
            return null;
        } else  {
            // return object
            count--;
            Object obj = queue[rIndex];
            queue[rIndex] = null;
            rIndex++;
            return obj;
        }
    }

    /**
     * Returns the total number of objects stored in the queue.
     *
     * @return The total number of objects in the queue.
     */
    public int getCount() {
        return count;
    }

    /**
     * Checks to see if the queue is empty.
     *
     * @return true if queue is empty, false otherwise.
     */
    public boolean isEmpty() {
        return (count == 0 ? true : false);
    }
}






there was a problem on here...

but i still confuse with it...

the program still broken..

This post has been edited by ioncrew: 15 Mar, 2008 - 09:19 AM
User is offlineProfile CardPM
+Quote Post

bhandari
RE: Fix It Again...
15 Mar, 2008 - 09:34 AM
Post #2

D.I.C Addict
Group Icon

Joined: 31 Jan, 2008
Posts: 747


Dream Kudos: 900
My Contributions
can you please describe your problem, this will help us in helping you better.


This post has been edited by bhandari: 15 Mar, 2008 - 09:34 AM
User is offlineProfile CardPM
+Quote Post

ioncrew
RE: Fix It Again...
15 Mar, 2008 - 01:44 PM
Post #3

New D.I.C Head
*

Joined: 5 Mar, 2008
Posts: 9

QUOTE(bhandari @ 15 Mar, 2008 - 10:34 AM) *

can you please describe your problem, this will help us in helping you better.



i'm tried to make a circular Queue, but when i try to compile then Run, the compiler said "Exception in thread "main" java.lang.NoSuchMethodError: main"
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Fix It Again...
15 Mar, 2008 - 06:12 PM
Post #4

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,327



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
Copy and paste the whole error message here. It will provide an insight into where the problem originates.
User is offlineProfile CardPM
+Quote Post

ioncrew
RE: Fix It Again...
16 Mar, 2008 - 02:07 AM
Post #5

New D.I.C Head
*

Joined: 5 Mar, 2008
Posts: 9

QUOTE(jayman9 @ 15 Mar, 2008 - 07:12 PM) *

Copy and paste the whole error message here. It will provide an insight into where the problem originates.



When i run it...

the compiler show an error massage

Exception in thread "main" java.lang.NoSuchMethodError: main[size=3]
User is offlineProfile CardPM
+Quote Post

1lacca
RE: Fix It Again...
16 Mar, 2008 - 04:54 AM
Post #6

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
How do you run it? If this is your only class, then you might want to take a look at this tutorial about the main method
User is offlineProfile CardPM
+Quote Post

letthecolorsrumble
RE: Fix It Again...
16 Mar, 2008 - 04:57 AM
Post #7

Student of The Sun
Group Icon

Joined: 7 Nov, 2007
Posts: 550



Thanked: 1 times
My Contributions
If you are trying to run the code you have pasted above, it will certainly give you an error message, as there is no main() method defined in the code.

In your other post you have posted a code that contains the main() method. Try using that. :)
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 08:41PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month