SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: help with java

  1. #1
    SitePoint Addict
    Join Date
    Oct 2001
    Posts
    359
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help with java

    Anyone like to help a newbie with java?

    I'm havin trouble reorganizing positions after a record is removed; for instance creating 5 positions and removing position 3 the positions become 1,2,4,5 (instead of 1,2,3,4 in order)

    Also instead of entering in the doc name to be deleted, can i enter the postion number? and how would I in the code?

    uuInOut class is just to read data being inputted from keyboard by the way

    java.zip
    uuInOut.class

    Thanks for any help

  2. #2
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Canada
    Posts
    174
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I downloaded your zip file but Im not sure I understand what you wanna do. Do you have an int value which keeps track of the position in the Queue? If so, what is the importance of this !? I dont understand why you would need to number the position of the elements.

    Mostly because it's somewhat of an efficieny. Everytime an element is remove you will need to renumber every element above that item. In the worse case scenario it would be the element in position one being deleted.

    Additionally, you are not following OOP principles by accessing QueueNode variables in the form instance.variable. QueueNode should include some access methods such as :

    setQueueNodeValue(int newVal)
    int getQueueNodeValue()

    I also dont understand why you initialize a new QueueNode and then set the variable = null.

    Example:
    Code:
     QueueNode start = new QueueNode(); 
           start = null;
    Then you go on to initialize it later?

    Kix
    Last edited by kix; May 7, 2002 at 15:06.

  3. #3
    SitePoint Addict
    Join Date
    Oct 2001
    Posts
    359
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have the position number there because it's better for readability (for example: being number 1 is top out of a the number of values inputted).
    I kinda have int position declarred in displaying all items, since I didn't know what other way to do it.

    start = null: sets up an empty queue shouldn't affect new QueueNode where I initialized it at the start.. but again I'm a new to java and haven't a clue what I'm talkin about.

    If you set the class uuInOut you'll be able to run the program and see what's wrong?
    Last edited by random; May 7, 2002 at 15:37.

  4. #4
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Canada
    Posts
    174
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe you could give an example of how this is suppose to work. Sorry if I'm not catching onto it. The logic behind a Queue is FIFO (first in first out), the order is determined by when it was entered. So removing elements at random...it's not really a property of a queue. Maybe you want a linked list!? That sounds like the better data structure in this situation.

    I don't have JDK installed on this computer so I can't compile it. But just give an example of what happens and what you're trying to achieve. Maybe in a little more detail than you did in your original post.

    Kix

  5. #5
    SitePoint Addict
    Join Date
    Oct 2001
    Posts
    359
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for replying again..

    Option 1: works as a FIFO, it removes the node that is at position number 1... this then organizes the positions properly (as it removes position one it does not stay positions 2, 3 for the others) - it does this automatically
    Option 2: this is just an add, it inserts a new node at the bottom of the list (or at the start of it if the list is null) - it asked me to enter document name, owner and size
    Option 3: Displays what is in the list in the following order that looks like:
    Code:
    Position     Document Name     Owner     Size (KB) 
       1         random1	       asdf1     20
       2         random2	       asdf2     40
       3         random3	       asdf3     30
    Option 4: This resets everything in the queue, pretty simple.
    Option 5: This is the problem one.. taking the above display, if i said to delete random2 it deletes it but leaves the following display:
    Code:
    Position     Document Name     Owner     Size (KB) 
       1         random1	       asdf1     20
       3         random3	       asdf3     30
    It would be nice to get the positions right, as the Option 1 does.. - it asks me to enter document name
    Option 6: Just displays how many nodes are listed in the queue.
    Option 7: This isn't started, supposed to add up everything in the data or temp.data to output the total size of all nodes listed.

  6. #6
    SitePoint Addict
    Join Date
    Oct 2001
    Posts
    359
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    aaah, got it working
    you couldn't tell me how to do option 7 though?

    let's say it added:
    Code:
    Position     Document Name     Owner     Size (KB) 
       1         random1	       asdf1     20
       2         random2	       asdf2     40
       3         random3	       asdf3     30
    It should calculate 20 + 40 + 30, but not sure how this would be done
    Last edited by random; May 7, 2002 at 19:19.

  7. #7
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Canada
    Posts
    174
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is not a very well written ADT. When you add a node you've got next pointing to the end and end pointing to the new node. What is the purpose of having them both point to each other? Again, you should not be using a queue as your DS because this isn't a queue. The properties in this DS are that of a list. Anyway..

    Code:
    public int size(){
      int val = 0;
      QueueNode temp = start; //you should be able to do this
      while( temp != null){
        val += temp.data;
        temp = temp.previous;
      }
      return val;
    }
    That should work..!

    Kix
    Last edited by kix; May 8, 2002 at 06:39.

  8. #8
    SitePoint Addict
    Join Date
    Oct 2001
    Posts
    359
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cheers kix, that works superb


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •