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

N

Newbie

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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,834
Latest member
BuyCannaLabsCBD

Latest Threads

Top