0

I am having three class one is linklist class and a LinkLLiat1 class and a LinkList2 class.can any one please help me to pass the getStudentID value to linklist class.

This is the LinkList1 class

   public class LinkList1 
    {
       public LinkList1 next;

       private int EmployeeID;
       private String EmployeeName;
       private String EmpContactNo;
       private String DOB;
       private String DateofJoined;
       private String DepatmentName;  


       public LinkList1 (int Employeeid, String Employeename, String EmpContactno, String dob, String Dateofjoined, String Depatmentname)
       {

           EmployeeID=Employeeid; // initialized class variable
           EmployeeName=Employeename; // initialized class variable
           EmpContactNo=EmpContactno; // initialized class variable
           DOB=dob; // initialized class variable
           DateofJoined=Dateofjoined; // initialized class variable
           DepatmentName=Depatmentname; // initialized class variable
       }
       public void DisplayLink()
       {
           System.out.println("("+EmployeeID+","+EmployeeName+","+EmpContactNo+","+DOB
                   +","+DateofJoined+","+DepatmentName.toUpperCase()+")");
       }
            public int getStudentID()
       {
           return EmployeeID;
       }
    }

this is in the LinkList2..

public class LinkList2 
{
    private LinkList1 first; // refer tp first link on the list
       public LinkList2 () // constructor
       {
           first = null; // no items on list yet
       }
       public boolean empty()
       {
           return (first==null);
       }
       public void insert(int Employeeid, String Employeename, String EmpContactno, String dob, String Dateofjoined, String Depatmentname)
       {
           LinkList1 newLinkList1= new LinkList1(Employeeid, Employeename, EmpContactno, dob, Dateofjoined, Depatmentname);
           newLinkList1.next= first; // newlink --> old first
           first = newLinkList1; // first --> new link

       }

       public LinkList1 delete() // elete first item
       {
           LinkList1 tem=first; //save reference to link
           first = first.next; //selete it: first--> old next
           return tem; // return deleted link
       }
  public int[] myListStudent(LinkList2 thelist)
  {
      int myStudentNo[]=new int[5];
       LinkList1 current = first;
       int i=0;
        while (thelist!=null) // until end of list
           {
            int a=current.getStudentID();
               myStudentNo[i]=current.getStudentID();
               current = current.next; //move to next link
           }

      return myStudentNo;

  }
       public void displaylist()
       {
           System.out.println(" ID, Name, Contact No" + 
                   "Date of Birth. Date of Joined, Work Department ID");
           LinkList1 current = first; // start at beginning of list
           while (current!=null) // until end of list
           {
               current.DisplayLink(); //print data
               current = current.next; //move to next link
           }
           System.out.println("");
           }



}

i need to get the getStudentID values from the above class to the myArray in which is in mainlinklist class..

    public class LinkList 
{




    public static void main(String[] args) 
    {
        LinkList2 thelist = new LinkList2(); // make new list

        thelist.insert(1, "ssd", "071123456", "9.10.1993", "10.11.2010", "HR");
        thelist.insert(12, "dcfs", "071123456", "9.10.1993", "10.11.2010", "ACC");

        thelist.displaylist();

         LinkList2 myStudent = new LinkList2();
         int myArray[];
         myArray=myStudent.myListStudent(thelist);
        while(!thelist.empty())
        {
            LinkList1 aLink = thelist.delete();
            System.out.println("Deleted");
            aLink.DisplayLink();
            System.out.println();
            System.out.println("");  
        }


    }


}

what i want to do is get the EmployeeID vlues in LinkList1 to LinkList2 and the to Linklist.. i want to collect the values EmployeeID .. i don't know many be i am doing to totally wrong .. :) which means from this myStudentNo in below to the MyArray in linklist..

 public int[] myListStudent(LinkList2 thelist)
      {
          int myStudentNo[]=new int[5];
           LinkList1 current = first;
           int i=0;
            while (thelist!=null) // until end of list
               {
                int a=current.getStudentID();
                   myStudentNo[i]=current.getStudentID();
                   current = current.next; //move to next link
               }

          return myStudentNo;

      }
5
  • can you explain what you try to do in LinkList1 class? what is purpose of LinkList1?why do not you combine LinkList1 and LinkList2 together? is LinkList1 supper class of LinkList2? – Kick Buttowski Commented May 18, 2014 at 22:04
  • linklist is the main class and LinkList is the node where i am getting values from the main and LinkList 2 i use to to the oerations like delete and add .. and iam using Netbeans and as this is an assginmnet i need to have three different classes :( and now i have to get the vlaues of myListStudent to the main class .. so i can get the values to do a search of The IDs in the linklist .. Commented May 18, 2014 at 22:10
  • please explain the usage of** LinkList1** class? Is your specification forced you to use 3 different classes? To me, you can combine LinkList1 and LinkList2 together to simplify your situation? Commented May 18, 2014 at 22:11
  • ya specification is like that need to have three class :( LinkList1 has the variables to collect the data that i put to linklist "main" class Commented May 18, 2014 at 22:17
  • Is it possible to post up the specification? Commented May 18, 2014 at 22:25

1 Answer 1

1

You could pass it through the constructor.

Eg. when you create an instance of the class do

CLASS name = new CLASS(variableToPass);

UPDATE:

When you create an instance of the class that you wish to pass it to, use the variable as an argument of the constructor of that class. I hope it is easier to understand now.

When you create a new instance of a class the constructor is called.

This is an example of a constructor:

public ClassName() {
}

This constructor takes no arguments and therefore creating an instance of that class is as follows:

ClassName class = new ClassName();

Constructors can also take arguments and set them to values:

int i = 0;

public ClassName(int i){
this.i = i;
}

ClassName class = new ClassName(1);

This would set the instance variable of i to the value of i given. this. refers to the instance variable.

You should add what you want to pass through the constructor this way.

Sign up to request clarification or add additional context in comments.

9 Comments

This was posted as an answer, but it does not attempt to answer the question. It should possibly be an edit, a comment, another question, or deleted altogether.
I don't understand how this doesn't attempt to answer the question. I edited it to show an example of what I meant. I'm not going to write all of his code for him.
at least, can you explain your answer in better way?
Is this any better? Sorry for not answering it well enough.
Thanks a lot Jake :) for trying to help me .. but still it is getting errors.. ill edit the question in detail :)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.