We help IT Professionals succeed at work.
Get Started

object returned but cannot access its methods?

OwenMoriarty
OwenMoriarty asked
on
321 Views
Last Modified: 2013-11-23
Three classes pasted below, this is a linked list implementation. I have a button on my GUI that should inform the user of the object in the front of the queue. I cannot access the methods of an employye object? Any pointers?

Tks,
Owen.


private void frontButtonActionPerformed(java.awt.event.ActionEvent evt)
 {
myQueue.front();
How do I access the methods or properties of my employee object?????
Netbeans autocomplete won't bring up any of these? I want to put one of it's
}
public class Node {
    private Object element;
    private Node next;
    
    public Node()
    {
        this(null,null);
    }
    public Node(Object e, Node n)
    {
        element = e;
        next = n;
    }
    public void setElement(Object newElement)
    {
        element = newElement;
    }
    public void setNext(Node newNext)
    {
        next = newNext;
    }
    public Object getElement()
    {
        return element;
    }
    public Node getNext()
    {
        return next;
    }
   
    }
################################################
 
public class Employee {
    private  int age,empNum;
    private String fName, lName;
    
    public Employee(int empNum, String fName, String lName, int age)
    {
        this.age = age;
        this.empNum = empNum;
        this.fName = fName;
        this.lName = lName;
    }
    
    public String getName()
    {
        String joinName;
        joinName = fName + lName;
        return joinName;
    }
    public int getAge()
    {
        return age;
    }
    public int getEmpNum()
    {
        return empNum;
    }
    @Override
    public String toString()
    {
        return empNum+ "\t" + fName+ " " + lName+ "\t" + age + "\n";
    }
 
}
##################################################
 
public class LinkedQueue 
{
    private Node head, tail;
    private int qSize;
    
    public LinkedQueue()
    {
        head = tail = null;
        qSize = 0;
    }
    public int size()
    {
        return qSize;
    }
    public Node getTail()
    {
        return tail;
    }
    public boolean isEmpty()
    {
    return ( head==tail );
    }
    public Object front() throws QueueEmptyException
    {if (isEmpty())
        throw new QueueEmptyException("Queue is empty");
     else
         return head.getElement();
    }
    
    public void append(Object obj)
    {
    Node node = new Node();
    node.setElement(obj);
    node.setNext(null);
    if(qSize == 0)
        head = node;
    else 
        tail.setNext(node);
    tail = node;
    qSize++;
    }
    public Object serve()throws QueueEmptyException
{
    Object obj;
    if(qSize == 0)
        throw new QueueEmptyException("Queue is empty");
    else 
    {
        obj = head.getElement();
        head = head.getNext();
        qSize--;
    }
    if(qSize == 0)
        tail = null;
    return obj;
    
}
}

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE