Help Please : - Retrieve object key held in an ordered linked list node

Discussion in 'Java' started by Newbie, Apr 6, 2004.

  1. Newbie

    Newbie Guest

    heres the deal,
    I have 3 seperate classes. ( 1. user Interface. 2.employee. 3.ordered
    linked list )

    1.
    user enters ID and NAME for the employee using JOptionPane which the values
    are then passed to the following method inside the userinterface class.

    public void setup(int id, String name) {
    emp = new Employee(); //Employee class instantiation
    emp.setKey( id ); //sets the ID var
    emp.setName( name ); //sets the NAME var
    orderedList.insert( emp ); //Ordered List instantiation insert
    }

    2.
    public class Employee implements Comparable {
    private String name;
    private int key;
    public int compareTo(Object o) {
    int result;
    Employee empl = (Employee) o;
    if (empl.key < key) { result = 1; }
    if (empl.key > key) { result = -1; }
    else { result = 0; }
    return result;
    }

    public void setKey(int newKey) { key = newKey; }
    public void setName(String Name) { name = Name; }
    public int getKey ( ) { return key; }
    public String getName() { return name; }
    public String toString() { return "Id : "+key+" Name :
    ame; }
    }

    3.
    ***** Snipped the insert ... etc methods *****

    private class Node {
    protected Object obj;
    protected Node next;

    public Node(Object obj, Node next) {
    this.obj = obj;
    this.next = next;
    }
    }
    How in hells teeth can I implement a "search" method in the OrderedList
    class that when an "int" is passed into the orderedlist class from the
    userinterface class (using JOptionPane again) I can search for a specific
    employee ID and then return the full contents of the Object with that
    key.??!!

    This has been driving me insane... I could really use some help with this as
    I dont have the knowledge or skill to achieve what I want to.


    Thankyou!
    Newbie, Apr 6, 2004
    #1
    1. Advertising

  2. Andrew Thompson, Apr 7, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tjerk Wolterink
    Replies:
    2
    Views:
    1,418
    Dimitre Novatchev
    Aug 24, 2006
  2. fool
    Replies:
    14
    Views:
    501
    Barry Schwarz
    Jul 3, 2006
  3. sangram
    Replies:
    16
    Views:
    1,978
  4. francesco

    Inserting a new node in an ordered linked list

    francesco, Mar 15, 2011, in forum: C Programming
    Replies:
    5
    Views:
    1,412
  5. DL

    Ordered list inside ordered list

    DL, Nov 9, 2009, in forum: Javascript
    Replies:
    6
    Views:
    317
    Dr J R Stockton
    Nov 21, 2009
Loading...

Share This Page