Results 1 to 5 of 5
  1. #1
    Nigel is offline Member
    Join Date
    Mar 2011
    Posts
    8
    Rep Power
    0

    Question how to link to differt classes

    hi,

    I'm in my first year of IT in Belgium and I'm currently making a program in blueJ with 2 classes: owners of pet and a second class: pets.
    My assignment is to create a method in the class pets that shows the records of the owner (name, age and sex)
    My questions is how do I do this? I suppose I need to create a link between the two classes or something similar?

  2. #2
    rp181 is offline Member
    Join Date
    Mar 2009
    Posts
    70
    Rep Power
    0

    Default

    Have your owner have those fields (name, etc). Then, make a method in the pet class to setOwner(Owner owner). Copy owner into a private variable (remeber, objects create references. When the owner class changes, the owner of the pet will always be updated). That way, you can do pet.getOwnerName(); Which would return the stored variable(e.g owner.getName()).

  3. #3
    Nigel is offline Member
    Join Date
    Mar 2011
    Posts
    8
    Rep Power
    0

    Default

    I don't know how to start my methode
    Do I start: public, String or int, displayOwnerRecords()?
    And then what?
    I also don't know how to "Copy owner into a private variable"
    I really am new to java, my apolagies for the noob questions, but I'm here to learn
    Thank you in advance for your patience

  4. #4
    rp181 is offline Member
    Join Date
    Mar 2009
    Posts
    70
    Rep Power
    0

    Default

    If you want it to directly display, it would be a public void.

  5. #5
    Nigel is offline Member
    Join Date
    Mar 2011
    Posts
    8
    Rep Power
    0

    Default

    public void toonEigenaarGegevens()
    {
    return naam + leeftijd + geslacht;
    }

    name age sex

    this is what i typed but now het gets the data from within the pets class and not from the owner class? How do i fix tis?
    I also receive a error message when I compile that he can't return a value for a void methode

Similar Threads

  1. jsf command link
    By Srikala in forum JavaServer Faces (JSF)
    Replies: 2
    Last Post: 06-29-2010, 02:38 PM
  2. Getting link attachment
    By dynamolalit in forum Advanced Java
    Replies: 0
    Last Post: 08-17-2009, 11:03 AM
  3. jsf command link
    By Srikala in forum JavaServer Faces (JSF)
    Replies: 1
    Last Post: 06-25-2009, 08:03 AM
  4. Replies: 6
    Last Post: 01-30-2009, 10:24 AM
  5. Link for 64 bit JDK.
    By aparna in forum New To Java
    Replies: 0
    Last Post: 03-19-2008, 02:15 PM

Posting Permissions

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